What Are GCD and LCM?
The Greatest Common Divisor (GCD) — also called Greatest Common Factor (GCF) or Highest Common Factor (HCF) — is the largest positive integer that divides each of the given numbers without a remainder. The Least Common Multiple (LCM) is the smallest positive integer divisible by all given numbers.
The Euclidean Algorithm
The Euclidean algorithm is the most efficient way to compute GCD: GCD(a, b) = GCD(b, a mod b), repeating until the remainder is 0. It runs in O(log n) time. For example: GCD(252, 105) → GCD(105, 42) → GCD(42, 21) → GCD(21, 0) = 21.
Relationship Between GCD and LCM
For two positive integers a and b: GCD(a, b) × LCM(a, b) = a × b. This identity allows LCM to be computed quickly once GCD is known.
Practical Uses
- Simplifying fractions: 18/24 → divide both by GCD(18,24)=6 → 3/4.
- Adding fractions: 1/4 + 1/6 → common denominator = LCM(4,6) = 12 → 3/12 + 2/12 = 5/12.
- Scheduling: Two events with periods of 4 and 6 days coincide every LCM(4,6) = 12 days.
Comments