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
- Type two or more whole numbers, separated by commas or spaces (for example 252, 198).
- Read the GCD and LCM at the top. "Coprime" tells you whether the numbers share no factor other than 1.
- Check the prime factorizations, and the GCD and LCM written as products of primes.
- 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 , divide by and keep the remainder: . Since every common divisor of and also divides ,
Repeat until the remainder is 0; the last nonzero remainder is the GCD.
LCM from the GCD. For two numbers,
and for several numbers you apply both rules one number at a time: , 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:
The last nonzero remainder is 18, so . Then .
Check with prime factors: and . Common primes, lowest powers: . All primes, highest powers: .
Three numbers: 12, 18 and 30. and .
Everyday uses of the GCD and the LCM
- Simplifying fractions: divided top and bottom by the GCD 18 gives in one step. Our fraction calculator does this automatically.
- Common denominators: to add , use the LCM 36 as the denominator: .
- 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, — 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
- Euclid, Elements, Book VII, Propositions 1–2 (D. E. Joyce edition, Clark University)
- Knuth, The Art of Computer Programming, Vol. 2, §4.5.2 The Greatest Common Divisor
- Weisstein, Greatest Common Divisor — Wolfram MathWorld
- Weisstein, Least Common Multiple — Wolfram MathWorld
Last updated: