GCD and LCM calculator
Enter two or more whole numbers. The greatest common divisor is the largest number dividing all of them; the least common multiple is the smallest number they all divide into.
Two or more, separated by spaces, commas, semicolons or new lines.
Result
- Greatest common divisor
- 6
- Least common multiple
- 36
- Prime factors of the GCD
- 2 × 3
How this is calculated
The Euclidean algorithm repeatedly replaces the larger number with the remainder of dividing it by the smaller, and stops when nothing is left over. It is over two thousand years old and still the fastest practical method. The LCM divides before multiplying, which keeps the intermediate value small enough to stay exact.
- gcd
- — the largest number dividing every input exactly
- lcm
- — the smallest number every input divides into exactly
- coprime
- — sharing no common factor beyond 1
Worked example
For 12 and 18 the Euclidean steps are: 18 mod 12 = 6, then 12 mod 6 = 0, so the GCD is 6. Its prime factors are 2 and 3. The LCM is 12 ÷ 6 × 18 = 36. Checking both: 6 divides 12 and 18, and 36 is divisible by both — and no smaller number is. For 17 and 5 the GCD is 1, which means they are coprime and their LCM is simply their product, 85.
How to use it
- Type two or more whole numbers, separated however you like.
- The GCD appears first; the LCM below it, when every value is non-zero.
- The prime factors of the GCD show where the common divisor comes from.
Limitations and assumptions
- Whole numbers only. Fractions have a GCD in a different sense that this tool does not compute.
- Negative numbers are accepted and their sign is ignored, since divisibility does not depend on sign.
- When any value is zero there is no least common multiple: every number divides zero, so there is no smallest such multiple. The tool reports the GCD and says the LCM does not exist.
- Very large inputs are refused rather than computed inexactly: beyond the safe integer range the result would be wrong without saying so.
Questions
What is the GCD used for?
Most commonly for reducing fractions: dividing numerator and denominator by their GCD gives lowest terms in one step. It also answers questions like the largest identical tile that fits a room exactly in both directions.
What is the LCM used for?
Finding a common denominator, and any question about things that repeat on different cycles — when two schedules next coincide, or the shortest length cut exactly by two different piece sizes.
What does coprime mean?
That the numbers share no factor other than 1, so their GCD is 1. For coprime numbers the LCM is just their product, which is why 17 and 5 have an LCM of 85.
Related calculators
This page has not yet had an editorial review.
