Skip to content

GCD and LCM Calculator

Greatest common divisor and least common multiple of several integers, with Euclid’s steps.

Your details

Two to 20 whole numbers, separated by commas or spaces. Negative numbers and 0 are allowed.

Results update as you type

Greatest common divisor (GCD)

18

Least common multiple (LCM)
2,772
Coprime?
No — they share the factor 18
Prime factorizations
252 = 2² × 3² × 7 · 198 = 2 × 3² × 11
GCD as prime factors
2 × 3²
LCM as prime factors
2² × 3² × 7 × 11

Step-by-step solution
  1. Euclid’s algorithm for GCD(252, 198):
  2. 252 = 1 × 198 + 54
  3. 198 = 3 × 54 + 36
  4. 54 = 1 × 36 + 18
  5. 36 = 2 × 18 + 0
  6. The last nonzero remainder is the GCD: GCD(252, 198) = 18
  7. LCM(252, 198) = 252 × 198 ÷ 18 = 2,772
  8. Prime factorization: 252 = 2² × 3² × 7
  9. Prime factorization: 198 = 2 × 3² × 11
  10. GCD = common primes with their lowest powers: 2 × 3² = 18
  11. LCM = every prime with its highest power: 2² × 3² × 7 × 11 = 2,772

The greatest common divisor (GCD) of two or more integers is the largest number that divides all of them exactly. The least common multiple (LCM) is the smallest positive number that all of them divide into. This calculator finds both at once for up to 20 integers, and shows how: every division of Euclid’s algorithm, the prime factorization of each number, and how the GCD and LCM are read from those factors.

You will meet these two numbers whenever you simplify a fraction (divide top and bottom by their GCD), add fractions with different denominators (the common denominator is the LCM), cut material into equal pieces with no waste, or work out when two repeating events next coincide.

The GCD is also called the greatest common factor (GCF) or highest common factor (HCF). The calculator accepts negative numbers and zero, works exactly with integers up to one trillion, and prints the LCM in full even when it is too large for an ordinary calculator display.

How to use this calculator

  1. Type two or more whole numbers, separated by commas or spaces (for example 252, 198).
  2. Read the GCD and LCM at the top. "Coprime" tells you whether the numbers share no factor other than 1.
  3. Check the prime factorizations, and the GCD and LCM written as products of primes.
  4. Open the steps to follow Euclid’s algorithm line by line — the format most teachers expect in written work.

The formula

Euclid’s algorithm. For a≥b>0a \ge b > 0, divide aa by bb and keep the remainder: a=qb+ra = qb + r. Since every common divisor of aa and bb also divides rr,

gcd⁡(a,b)=gcd⁡(b, a mod b),gcd⁡(a,0)=a\gcd(a, b) = \gcd(b,\ a \bmod b), \qquad \gcd(a, 0) = a

Repeat until the remainder is 0; the last nonzero remainder is the GCD.

LCM from the GCD. For two numbers,

lcm⁡(a,b)=∣a×b∣gcd⁡(a,b)\operatorname{lcm}(a, b) = \frac{|a \times b|}{\gcd(a, b)}

and for several numbers you apply both rules one number at a time: gcd⁡(a,b,c)=gcd⁡(gcd⁡(a,b),c)\gcd(a, b, c) = \gcd(\gcd(a, b), c), and likewise for the LCM.

With prime factors. Write each number as a product of primes. The GCD takes the primes common to all numbers with their lowest exponent; the LCM takes every prime that appears with its highest exponent.

Worked example

Two numbers: 252 and 198. Euclid’s algorithm:

  • 252=1×198+54252 = 1 \times 198 + 54
  • 198=3×54+36198 = 3 \times 54 + 36
  • 54=1×36+1854 = 1 \times 36 + 18
  • 36=2×18+036 = 2 \times 18 + 0

The last nonzero remainder is 18, so gcd⁡(252,198)=18\gcd(252, 198) = 18. Then lcm⁡(252,198)=252×19818=2772\operatorname{lcm}(252, 198) = \frac{252 \times 198}{18} = 2772.

Check with prime factors: 252=22×32×7252 = 2^2 \times 3^2 \times 7 and 198=2×32×11198 = 2 \times 3^2 \times 11. Common primes, lowest powers: 2×32=182 \times 3^2 = 18. All primes, highest powers: 22×32×7×11=27722^2 \times 3^2 \times 7 \times 11 = 2772.

Three numbers: 12, 18 and 30. gcd⁡=6\gcd = 6 and lcm⁡=180\operatorname{lcm} = 180.

Everyday uses of the GCD and the LCM

  • Simplifying fractions: 198252\frac{198}{252} divided top and bottom by the GCD 18 gives 1114\frac{11}{14} in one step. Our fraction calculator does this automatically.
  • Common denominators: to add 112+118\frac{1}{12} + \frac{1}{18}, use the LCM 36 as the denominator: 336+236=536\frac{3}{36} + \frac{2}{36} = \frac{5}{36}.
  • Cutting without waste: a floor of 252 cm × 198 cm can be covered by whole square tiles of at most 18 cm — the GCD.
  • Schedules: buses leaving every 12 and 18 minutes leave together again after 36 minutes — the LCM.
  • Gears and cycles: two gears with 24 and 36 teeth return to the same position after lcm(24, 36) = 72 teeth have passed.

GCD vs LCM at a glance

GCD LCM
Question Largest number that divides them all Smallest number they all divide
Size At most the smallest (nonzero) number At least the largest number
From prime factors Common primes, lowest powers All primes, highest powers
Coprime numbers 1 Their product

For two positive integers, gcd⁡(a,b)×lcm⁡(a,b)=a×b\gcd(a, b) \times \operatorname{lcm}(a, b) = a \times b — a handy way to check your answer.

Frequently asked questions

What is the difference between GCD and LCM?

The GCD is the largest number that divides every number in your list; the LCM is the smallest positive number that is a multiple of all of them. For 12 and 18, the GCD is 6 and the LCM is 36.

How does Euclid’s algorithm work?

Divide the larger number by the smaller and keep the remainder. Replace the pair with (smaller number, remainder) and repeat. When the remainder reaches 0, the previous remainder is the GCD. It is fast even for very large numbers.

What does coprime mean?

Two integers are coprime (relatively prime) when their only common positive divisor is 1, such as 35 and 64. Their LCM is then simply their product.

What are GCD and LCM when one number is 0?

Every integer divides 0, so GCD(0, n) = n. The LCM involving 0 is 0 by convention. The GCD of only zeros is undefined, so the calculator asks for at least one nonzero number.

Do negative numbers change the result?

No. Divisibility ignores the sign, so GCD(−12, 18) = 6 and the LCM is 36. Both are always given as positive numbers.

Is GCF or HCF the same as GCD?

Yes. Greatest common factor (GCF), highest common factor (HCF) and greatest common divisor (GCD) are three names for the same number.

Sources

Last updated:

More Math calculators

People also use