GCD and LCM
Greatest Common Denominator and Least Common Multiple
Last updated
Greatest Common Denominator and Least Common Multiple
Last updated
GCD (Greatest Common Denominator)
How to find the greatest common denominator (gcd) of two numbers quickly?
Euclid's method of finding GCD
Time Complexity:
Space Complexity:
Euclid's algorithm works because it leverages two fundamental properties of the greatest common divisor (GCD):
If d
is a divisor of two numbers a
and b
, for a
>= b
, then d
is also a divisor of aākb
for any integer k
.
This is true because d
is still a factor of a
and b
, which can be taken out from each expression
This implies that the GCD of a
and b
is the same as the GCD of b
and
To find the LCM, there is a math formula that relates LCM to GCD, which makes calculation easy.
Here is a great proof by ChatGPT that explains why: