Home › Math › GCD and LCM Calculator

GCD and LCM Calculator

Enter two or three positive whole numbers. You get the greatest common divisor, the least common multiple and each number's prime factorization.

Greatest common divisor

—

Least common multiple
—
Prime factorizations
—

Two answers to "what do these numbers share?"

The greatest common divisor (GCD, also called the greatest common factor or highest common factor) is the biggest whole number that divides every input with no remainder. The least common multiple (LCM) is the smallest number that every input divides into. One looks down to shared factors, the other up to a shared target.

For 12 and 18, the GCD is 6 and the LCM is 36. The factorizations are 12 = 2^2 × 3; 18 = 2 × 3^2. Add a third number, 30, and the GCD stays 6 while the LCM grows to 180.

Euclid's shortcut

gcd(a, b) = gcd(b, a mod b), repeated until the remainder is 0
lcm(a, b) = a × b ÷ gcd(a, b)
For three numbers: gcd(a, b, c) = gcd(gcd(a, b), c), and the same for the LCM

"a mod b" means the remainder when a is divided by b. Euclid set out this method around 300 BC, and it is still how computers do it, because it needs only a handful of steps even for huge numbers.

Worked by hand for 1,071 and 462:

  • 1,071 ÷ 462 leaves 147
  • 462 ÷ 147 leaves 21
  • 147 ÷ 21 leaves 0, so the GCD is 21

Dividing by the GCD before multiplying, as the calculator does, keeps the LCM from overflowing on big inputs.

Reading the prime factorizations

Write each number as a product of primes. The GCD takes every prime the numbers share, at its lowest power. The LCM takes every prime that appears anywhere, at its highest power. For 12 = 2² × 3 and 18 = 2 × 3², that gives a GCD of 2 × 3 = 6 and an LCM of 2² × 3² = 36.

Common pairs and what they share
NumbersGCDLCM
8 and 9172
12 and 18636
48 and 18012720
1,071 and 4622123,562
4, 6 and 10260

Everyday uses

  • Adding fractions: the LCM of the denominators is the lowest common denominator. 5/12 + 7/18 becomes 15/36 + 14/36 = 29/36.
  • Simplifying fractions and ratios: divide top and bottom by the GCD. 48/180 has a GCD of 12, so it reduces to 4/15.
  • Scheduling: two buses every 12 and 18 minutes leave together again after 36 minutes, the LCM.
  • Tiling and cutting: the largest square tile that fits a 48 × 180 cm area exactly is 12 cm, the GCD.

When repeating events line up

The LCM also answers "how often do these cycles coincide?" for more than two cycles. If one machine is serviced every 4 weeks, another every 6 and a third every 10, all three fall due in the same week only every 60 weeks. Grouping the work into that week saves a shutdown, while the GCD of 2 weeks is the longest regular interval that lands on every service date.

The same idea applies to gears. With a 12-tooth gear driving an 18-tooth gear, the same pair of teeth meets again after 36 teeth have passed, which is 3 turns of the small gear and 2 of the large one.

Mistakes to avoid

  • Mixing up the two. The GCD can never be larger than the smallest input; the LCM can never be smaller than the largest.
  • Assuming the product is the LCM. It only is when the numbers share no factor, as with 8 and 9.
  • Using decimals. GCD and LCM are defined for whole numbers. To compare 1.5 and 2.5, scale both by 10 first.

The third box is optional: leave it at 0 for two numbers. Consecutive Fibonacci numbers always have a GCD of 1. For percentages of the result, use the percentage calculator; for quantities in recipes, the cooking converter.

GCD and LCM questions

What is the GCD of 12 and 18?

6. Both are multiples of 6, and no larger number divides both.

How do I find the LCM from the GCD?

Multiply the two numbers and divide by their GCD. For 12 and 18: 216 ÷ 6 = 36.

What does it mean if the GCD is 1?

The numbers are coprime: they share no prime factor, and their LCM is simply their product.

Can I use negative numbers?

GCD and LCM are normally given as positive. Enter the absolute values.

Related calculators