Greatest common divisor and least common multiple: the Euclidean algorithm explained
The greatest common divisor (GCD, also called the highest common factor) of two integers is the largest number that divides both. The least common multiple (LCM) is the smallest positive number both divide into. GCDs simplify fractions; LCMs give common denominators and solve scheduling problems (“when will two cycles line up again?”).
The solver uses the Euclidean algorithm, one of the oldest algorithms still in daily use (described by Euclid around 300 BC), and the extended version that also produces Bézout coefficients.
Key formulas
gcd(a, b) = gcd(b, a mod b), stop when the remainder is 0lcm(a, b) = |a·b| / gcd(a, b)a·x + b·y = gcd(a, b) for some integers x, yWorked examples
Find gcd(252, 198).
- 252 = 1 × 198 + 54
- 198 = 3 × 54 + 36
- 54 = 1 × 36 + 18
- 36 = 2 × 18 + 0
Simplify 1071/462.
- 1071 = 2 × 462 + 147; 462 = 3 × 147 + 21; 147 = 7 × 21 + 0.
- GCD = 21: 1071/21 = 51, 462/21 = 22.
Bus A leaves every 12 minutes and bus B every 18 minutes, both at 8:00.
- lcm(12, 18) = 12 × 18 / gcd(12, 18) = 216 / 6 = 36.
Find the inverse of 17 modulo 31.
- Extended Euclid gives 17 × 11 + 31 × (−6) = 1.
- So 17 × 11 ≡ 1 (mod 31).
Add 5/12 + 7/18.
- LCM(12, 18) = 12 × 18 ÷ GCD(12, 18) = 216 ÷ 6 = 36.
- Rewrite: 5/12 = 15/36 and 7/18 = 14/36.
- Add the numerators: 29/36, which cannot be simplified (GCD(29, 36) = 1).
12, 18A panel is 84 cm by 126 cm. What is the largest square tile that covers it exactly, and how many are needed?
- The tile side must divide both lengths, so take the GCD: GCD(84, 126) = 42 cm.
- Tiles along each side: 84 ÷ 42 = 2 and 126 ÷ 42 = 3.
84, 126Why the Euclidean algorithm works
Any number that divides both a and b also divides a − qb, the remainder. So the pair (a, b) and the pair (b, a mod b) have exactly the same common divisors, and therefore the same greatest one. The numbers shrink quickly — at least by half every two steps — which is why the algorithm handles numbers with hundreds of digits instantly.
GCD or LCM? A quick way to decide
- Splitting things into equal groups with nothing left over, or the largest piece that fits several lengths → GCD.
- Finding when repeating events next happen together, or a common denominator → LCM.
- The two answers are linked: for two positive whole numbers, GCD × LCM = the product of the numbers.
Common mistakes to avoid
- Confusing GCD with LCM (the GCD is never larger than the smaller number; the LCM is never smaller than the larger).
- Multiplying two numbers to get the LCM when they share factors.
- Stopping at a zero remainder and reporting 0 instead of the previous remainder.
Frequently asked questions
What is the GCD of a number and 0?
What does it mean if the GCD is 1?
Can I find the GCD of more than two numbers?
Why does GCD × LCM equal the product of the two numbers?
Can the LCM be smaller than one of the numbers?
Related tools and guides
Educational content. Results are computed in your browser with standard double-precision arithmetic; double-check anything with legal, financial, medical, or safety consequences. Spotted an error? Tell us and we will correct it.