LCM and GCD Calculator

Find the least common multiple and greatest common divisor (HCF) of two to four numbers, with the prime factors worked out step by step.

Your details

Optional. Leave at 0 to use only two numbers.

Optional. Leave at 0 to skip.

LCM (least common multiple)

36

GCD / HCF (greatest common divisor)
6
Coprime?
No
Prime factors
12 = 2² × 3 · 18 = 2 × 3²

Visual breakdown

  • 12
  • 18

  1. 1

    Break each number into prime factors

    divide by 2, 3, 5, 7 … until only 1 is left

    = 12 = 2² × 3; 18 = 2 × 3²

    = 2 numbers factored

  2. 2

    GCD: the shared primes, at their lowest power

    multiply each prime found in every number, lowest power

    = 2 × 3

    = 6

  3. 3

    LCM: every prime, at its highest power

    multiply each prime that appears anywhere, highest power

    = 2² × 3²

    = 36

  4. 4

    Check: GCD × LCM equals the two numbers multiplied

    gcd(a, b) × lcm(a, b) = a × b

    = 6 × 36

    = 216

What this calculates

Enter two, three or four whole numbers and this finds their least common multiple (LCM) and greatest common divisor (GCD, also called the HCF), shows the prime factors of each, and says whether they are coprime.

The formula

Prime factors

write each number as a product of primes, such as 12 = 2² × 3

GCD (HCF)

the product of the primes in every number, each at its lowest power

LCM

the product of every prime that appears, each at its highest power

Two numbers

GCD(a, b) × LCM(a, b) = a × b

Worked example

Adding a third number, 30 = 2 × 3 × 5, keeps the GCD at 6 and brings in a 5, so the LCM becomes 2² × 3² × 5 = 180.

When to use it, and the mistakes to avoid

Use it to find a common denominator for fractions, to simplify a fraction or ratio, for maths homework on HCF and LCM, and for timing problems where repeating events need to line up.

The mistakes that cost the most:

  • Multiplying the numbers for the LCM. 12 × 18 = 216 is a common multiple, but not the least — that is 36.
  • Taking the wrong powers. The GCD takes each shared prime at its lowest power; the LCM takes every prime at its highest.
  • Leaving a prime out of the LCM. A prime in only one number still goes in.
  • Using GCD × LCM = product for three numbers. It only works for two.
  • Forgetting 1 is always a common divisor. If nothing else divides them all, the GCD is 1, not 0.

FAQ

What is the LCM?

The least common multiple is the smallest number that every one of the numbers divides into exactly. The LCM of 12 and 18 is 36: it is in the 12 times table (12 × 3) and the 18 times table (18 × 2), and no smaller number is in both.

What is the GCD, or HCF?

The greatest common divisor - also called the highest common factor (HCF) or greatest common factor (GCF) - is the largest number that divides every one of the numbers exactly. The GCD of 12 and 18 is 6.

How do I find the LCM and GCD by prime factors?

Break each number into primes: 12 = 2² × 3 and 18 = 2 × 3². For the GCD, take the primes they share at their lowest power: 2 × 3 = 6. For the LCM, take every prime at its highest power: 2² × 3² = 36.

Is there a link between the LCM and GCD?

For two numbers, yes: GCD × LCM = the two numbers multiplied. 6 × 36 = 216 = 12 × 18. So once you have one, you can find the other. This does not hold for three or more numbers.

What does coprime mean?

Two numbers are coprime when their GCD is 1 - they share no factor except 1, like 8 and 9. Their LCM is then simply the two multiplied together: 72.

Where are the LCM and GCD used?

The LCM gives the lowest common denominator for adding fractions, and tells you when repeating events line up - buses every 12 and 18 minutes leave together every 36 minutes. The GCD simplifies fractions and ratios, and finds the largest equal pieces something can be cut into.

Related calculators