LCM and GCD Calculator

Find the least common multiple and greatest common divisor of two or more integers, with the prime factorization of each number.

Result

LCM (least common multiple)

180

GCD / GCF (greatest common divisor)
6
Prime factorization
12 = 2² × 3; 18 = 2 × 3²; 30 = 2 × 3 × 5
Numbers used
3

Type two or more whole numbers and this calculator finds their least common multiple (LCM) and greatest common divisor (GCD, also called greatest common factor or GCF). It also lists the prime factorization of each number so you can follow the reasoning.

Formula

GCD: product of the common primes with the lowest exponent (or Euclid: gcd(a, b) = gcd(b, a mod b)). LCM: product of all primes with the highest exponent; for two numbers, lcm(a, b) = a × b ÷ gcd(a, b).

How it works

Type two or more whole numbers separated by commas, spaces or semicolons. The calculator uses the Euclidean algorithm for the GCD and the identity lcm(a, b) = a × b ÷ gcd(a, b), applied number by number, for the LCM. Negative numbers are treated by their absolute value, zeros and decimals are ignored, and the prime factorization of each number is shown so you can check the result by hand.

How to find the LCM and GCD with prime factors

Write each number as a product of primes. The GCD is the product of the primes that appear in every number, each with its lowest exponent. The LCM is the product of every prime that appears in any number, each with its highest exponent.

For larger numbers, the Euclidean algorithm is faster for the GCD: replace the larger number with the remainder of dividing it by the smaller one, and repeat until the remainder is zero. Then lcm(a, b) = a × b ÷ gcd(a, b). This is how the calculator works, applying it number by number for longer lists.

Worked example: 12, 18 and 30

Prime factors: 12 = 2² × 3, 18 = 2 × 3² and 30 = 2 × 3 × 5. The primes common to all three are 2 and 3, each with lowest exponent 1, so the GCD is 2 × 3 = 6. The LCM takes 2², 3² and 5: 4 × 9 × 5 = 180.

Check: 180 ÷ 12 = 15, 180 ÷ 18 = 10 and 180 ÷ 30 = 6, all whole numbers, and no smaller number works for all three. Likewise 12 ÷ 6, 18 ÷ 6 and 30 ÷ 6 are exact. For just two numbers, such as 8 and 12, the GCD is 4 and the LCM is 24.

When to use the LCM and when the GCD

Use the LCM when things repeat and you want to know when they line up: two buses leaving every 12 and 18 minutes meet again after 36 minutes. It is also the least common denominator for adding fractions, which the fraction calculator does for you.

Use the GCD when you split things into equal groups as large as possible: 12 red and 18 blue marbles can be packed into at most 6 identical bags (2 red and 3 blue each). It is also what reduces a fraction to lowest terms: 18/12 divided by 6 becomes 3/2.

Rules, edge cases and tips

The GCD of numbers that share no prime factor is 1 (they are called coprime), and their LCM is simply their product: for 8 and 15, GCD 1 and LCM 120. For two numbers, LCM × GCD always equals the product of the numbers, a quick way to check your work.

The calculator accepts commas, spaces or semicolons between numbers. Negative values are treated by their absolute value, while zeros and decimals are ignored because LCM and GCD are defined for nonzero integers. Very large lists can produce a huge LCM; results above about 9 quadrillion are not shown to avoid precision errors.

Frequently Asked Questions

What is the relationship between LCM and GCD?
For two positive integers, LCM × GCD = a × b. For 12 and 18: GCD 6, LCM 36, and 6 × 36 = 216 = 12 × 18. This shortcut does not hold for three or more numbers.
What is the difference between LCM and GCD?
The LCM is the smallest number that all your numbers divide into. The GCD is the largest number that divides all of them. For 12 and 18, the LCM is 36 and the GCD is 6.
Is GCF the same as GCD?
Yes. Greatest common factor (GCF), greatest common divisor (GCD) and highest common factor (HCF) are three names for the same number.
How do I find the LCM of three numbers?
Find the LCM of the first two, then the LCM of that result with the third. For 12, 18 and 30: lcm(12, 18) = 36 and lcm(36, 30) = 180.
What is the LCM used for in fractions?
It gives the least common denominator. To add 5/12 and 7/18, use 36: 15/36 + 14/36 = 29/36.