Skip to content
Math

GCF and LCM Calculator

Find the greatest common factor and least common multiple of 2 to 50 whole numbers, with the prime factorization of every number.

Free ยท no sign-up Runs in your browser
Enter 2 to 50 positive whole numbers separated by commas or spaces, for example: 12, 18, 30. Each number can be up to 1,000,000,000,000. Do not use thousands separators.

How to use the calculator

Enter between 2 and 50 positive whole numbers, separated by commas, spaces or new lines, and press Calculate. Each number can be as large as 1,000,000,000,000 (one trillion). Do not use thousands separators, because a comma starts a new number.

The result shows:

  • the greatest common factor (GCF), also called the greatest common divisor (GCD) or highest common factor (HCF)
  • the least common multiple (LCM), written out in full even when it has dozens of digits
  • the prime factorization of the LCM and of every number you entered

How it works

The GCF is found with the Euclidean algorithm: replace the larger number by the remainder of dividing it by the smaller one, and repeat until the remainder is zero. The last non-zero value is the GCF. For more than two numbers, the GCF of the first two is combined with the third, and so on.

The LCM of two numbers is a × b ÷ GCF(a, b), applied one number at a time. Whole-number arithmetic with no size limit is used, so the LCM is exact even when it is far larger than a normal calculator can display.

Prime factors are found by trial division: divide by 2, then 3, then by candidates up to the square root of what is left.

Worked example

Take 12, 18 and 30.

  • 12 = 2² × 3
  • 18 = 2 × 3²
  • 30 = 2 × 3 × 5

The GCF takes each prime that appears in every number, with its smallest power: 2 × 3 = 6.

The LCM takes every prime that appears in any number, with its largest power: 2² × 3² × 5 = 180.

You can check the link between the two for a pair of numbers: for 12 and 18, the GCF is 6 and the LCM is 36, and 6 × 36 = 216 = 12 × 18.

Good to know

  • If the GCF is 1, the numbers are called coprime (or relatively prime): they share no prime factor.
  • The LCM is useful for adding fractions (it gives the lowest common denominator) and for finding when repeating events line up again.
  • The GCF is useful for simplifying fractions and ratios and for splitting things into equal groups.
  • The number 1 has no prime factors, so it never changes the LCM and always makes the GCF equal to 1.

Frequently asked questions

What is the difference between GCF and LCM?

The greatest common factor is the largest number that divides all of your numbers exactly. The least common multiple is the smallest number that all of your numbers divide into exactly. The GCF is never larger than the smallest number, and the LCM is never smaller than the largest number.

Are GCF, GCD and HCF the same thing?

Yes. Greatest common factor, greatest common divisor and highest common factor are three names for the same value.

Why can the LCM be so large?

When the numbers share few prime factors, the LCM is close to their product. With many large numbers the LCM can have dozens or hundreds of digits. The calculator uses exact whole-number arithmetic, so every digit shown is correct.

Can I use zero, negative numbers or decimals?

No. The calculator accepts positive whole numbers from 1 to 1,000,000,000,000. Zero has no meaningful LCM, and the GCF and LCM of negative numbers are the same as for their positive values.