A GCD and LCM calculator that shows its working
This GCD calculator finds the greatest common divisor, also called the greatest common factor (GCF), and the least common multiple of 2 to 10 whole numbers. It does more than give the answer: it writes out the Euclidean algorithm line by line, shows the prime factorization with the shared factors highlighted and, if you ask, adds the subtraction method, the list of factors and Bézout's identity. Handy for checking homework.
How to use it
- In "Whole numbers (2 to 10)", type your numbers separated by commas, spaces or semicolons, for example
60, 42. - The "GCD (greatest common divisor)" and "LCM (least common multiple)" boxes fill in straight away. A line tells you whether the numbers are coprime, and for two numbers a "Check" line multiplies the results.
- Tick "Subtraction method", "List of factors" or "Bézout's identity" to add those methods to the "Steps". "Prime factorization" is ticked by default.
- "Copy the result" copies the answer and every step, ready to paste into your notes.
Three ways to find the GCD
The greatest common factor of two numbers is the largest whole number that divides both. The least common multiple is the smallest number other than 0 that both divide into. Take 60 and 42.
Listing factors. The factors of 42 are 1, 2, 3, 6, 7, 14, 21 and 42. The ones that also divide 60 are 1, 2, 3 and 6, so the GCD is 6.
Euclidean algorithm. Divide the larger number by the smaller: 60 = 1 × 42 + 18. Then divide 42 by the remainder: 42 = 2 × 18 + 6. Then 18 = 3 × 6 + 0. The remainder is 0, so the last divisor, 6, is the GCD. This method stays fast even with huge numbers.
Prime factorization. 60 = 2² × 3 × 5 and 42 = 2 × 3 × 7. For the GCD, take the shared primes with their lowest power: 2 × 3 = 6. For the LCM, take every prime with its highest power: 2² × 3 × 5 × 7 = 420.
For two numbers, GCD × LCM always equals a × b: 6 × 420 = 2,520 = 60 × 42. The tool shows this on the "Check" line.
Where you will use the GCD and LCM
- Reducing fractions: divide the top and bottom by their GCD. 42/60 becomes 7/10 after dividing by 6.
- Finding a common denominator: the LCM of the denominators is the least common denominator. For 1/4 + 1/6, LCM(4, 6) = 12, so 3/12 + 2/12 = 5/12.
- Sharing problems: a teacher has 60 pencils and 42 erasers and wants identical kits with nothing left over. The largest number of kits is 6, each with 10 pencils and 7 erasers.
- The hot dog problem: hot dogs come in packs of 10 and buns in packs of 8. LCM(10, 8) = 40, so 4 packs of hot dogs and 5 packs of buns match exactly.
With "Bézout's identity" ticked, the tool also finds whole numbers u and v such that 60u + 42v = 6, here u = −2 and v = 3, using the extended Euclidean algorithm laid out as a table.
Frequently asked questions
How do I find the GCD of three or more numbers?
Find the GCD of the first two, then the GCD of that result and the third number, and so on. For 12, 18 and 30: GCD(12, 18) = 6, then GCD(6, 30) = 6. The LCM works the same way: LCM(12, 18) = 36, then LCM(36, 30) = 180.
What does "coprime" mean?
Two numbers are coprime, or relatively prime, when their GCD is 1: their only common factor is 1. 8 and 15 are coprime even though neither is a prime number, and their LCM is simply their product, 120.
What happens with 0 or negative numbers?
Every whole number divides 0, so GCD(0, 15) = 15 and the LCM is 0. The GCD of two zeros is not defined, and the tool tells you so. Minus signs are ignored, because the GCD and LCM are worked out from absolute values.