GCD and LCM Calculator

Enter two or more whole numbers to get their greatest common divisor (GCD, also called HCF or GCF) and least common multiple (LCM). The calculator also writes out each number's prime factorization and the steps of Euclid's algorithm, so you can show the working in class.

Runs in your browser — nothing is uploaded

Useful for:School students

How to use it

  1. Type the numbers separated by spaces or commas, for example 12, 18, 30. You can enter from 2 to 20 numbers up to one trillion.
  2. Read the GCD and the LCM at the top.
  3. Check the prime factorizations: the GCD uses the primes all numbers share (lowest powers), the LCM uses every prime (highest powers).
  4. Follow Euclid's algorithm for the first two numbers to see another way to reach the GCD.

Common uses

  • Simplifying fractions: divide by the GCD of the numerator and denominator.
  • Finding a common denominator: use the LCM of the denominators.
  • Solving word problems such as “when will two buses arrive together again?”
  • Splitting items into equal groups with nothing left over.
  • Checking homework on prime factorization.

Examples

NumbersResult
12, 18GCD 6 · LCM 3612 = 2² × 3, 18 = 2 × 3².
8, 12, 20GCD 4 · LCM 120LCM = 2³ × 3 × 5.
48, 180GCD 12 · LCM 720Euclid: 180 = 3 × 48 + 36, 48 = 1 × 36 + 12, 36 = 3 × 12 + 0.
17, 31GCD 1 · LCM 527Coprime numbers: their LCM is simply their product.

Frequently asked questions

What is the difference between GCD and LCM?

The GCD is the largest number that divides all the given numbers. The LCM is the smallest number that all of them divide into. For 12 and 18 the GCD is 6 and the LCM is 36.

How do you find the GCD with prime factorization?

Write each number as a product of primes and multiply the primes they have in common, each with its lowest power. 12 = 2² × 3 and 18 = 2 × 3², so GCD = 2 × 3 = 6.

How does Euclid's algorithm work?

Divide the larger number by the smaller and keep the remainder. Then divide the previous divisor by that remainder, and repeat until the remainder is 0. The last non-zero remainder is the GCD.

Is there a quick formula linking GCD and LCM?

For two numbers, GCD × LCM = a × b. So LCM(12, 18) = 12 × 18 ÷ 6 = 36. This shortcut only works for two numbers at a time.