Free Tools · Math & School
LCM & GCF Calculator
Enter two or more whole numbers to get the least common multiple and greatest common factor, with the full working shown two ways.
GCF / HCF
6
Greatest common factor
LCM
180
Least common multiple
Method 1: Prime factorization
- 12 = 22 × 3
- 18 = 2 × 32
- 30 = 2 × 3 × 5
- GCF = lowest power of each prime that appears in every number = 2 × 3 = 6
- LCM = highest power of every prime that appears = 22 × 32 × 5 = 180
Method 2: Euclidean algorithm (GCF)
- GCF(12, 18)
- 18 = 1 × 12 + 6
- 12 = 2 × 6 + 0
- Remainder is 0, so GCF(12, 18) = 6
- GCF(6, 30)
- 30 = 5 × 6 + 0
- Remainder is 0, so GCF(6, 30) = 6
For more than two numbers, take them two at a time: GCF(a, b, c) = GCF(GCF(a, b), c), and likewise LCM(a, b, c) = LCM(LCM(a, b), c).
How the LCM and GCF calculator works
Prime factorization method
Every whole number above 1 can be written as a product of primes in exactly one way. Once each number is broken down:
- GCF = multiply the primes that appear in every number, each raised to its lowest power.
- LCM = multiply every prime that appears in any number, each raised to its highest power.
Euclidean algorithm for the greatest common factor
The Euclidean algorithm uses one fact: the GCF of two numbers doesn't change if you replace the larger one with the remainder after dividing by the smaller. Write a = q × b + r, then repeat with b and r. When the remainder reaches 0, the last non-zero remainder (the last divisor) is the GCF.
Getting the LCM from the GCF
For two numbers, LCM(a, b) = a × b ÷ GCF(a, b), because the product counts every shared prime factor twice and dividing by the GCF removes one copy. For three or more numbers, combine them in pairs: LCM(a, b, c) = LCM(LCM(a, b), c), and the same for the GCF.
Very large results are computed with exact integer arithmetic, so the LCM of big numbers is never rounded.
Worked examples
Example 1: LCM and GCF of 12, 18 and 30
12 = 2² × 3, 18 = 2 × 3², 30 = 2 × 3 × 5. The primes in all three are 2 and 3, each at lowest power 1, so the GCF is 2 × 3 = 6. Taking the highest power of every prime gives 2² × 3² × 5, so the LCM is 180.
Example 2: GCF of 84 and 126 by the Euclidean algorithm
126 = 1 × 84 + 42, then 84 = 2 × 42 + 0. The remainder is 0, so the GCF is 42. Then LCM = 84 × 126 ÷ 42 = 10,584 ÷ 42 = 252. Check: 252 × 42 = 10,584 = 84 × 126.
Example 3: When will three buses line up?
Buses leave a station every 8, 9 and 21 minutes, all at 7:00 a.m. 8 = 2³, 9 = 3², 21 = 3 × 7, so the LCM is 2³ × 3² × 7 = 504 minutes. They next leave together 8 hours and 24 minutes later, at 3:24 p.m. The GCF of 8, 9 and 21 is 1.
Frequently asked questions
What's the difference between GCF, GCD and HCF?
Nothing but the name. Greatest common factor (GCF), greatest common divisor (GCD) and highest common factor (HCF) all mean the largest whole number that divides every number in the set with no remainder.
What is the LCM used for?
The least common multiple is the smallest number every number in the set divides into. You use it to find a common denominator when adding fractions (the LCM of 4 and 6 is 12, so 1/4 + 1/6 = 3/12 + 2/12 = 5/12) and to solve timing problems like when two repeating events will line up again.
Is LCM × GCF always equal to the product of the numbers?
For exactly two positive numbers, yes: LCM(a, b) × GCF(a, b) = a × b. It doesn't hold for three or more numbers. For example, LCM(2, 4, 8) × GCF(2, 4, 8) = 8 × 2 = 16, but 2 × 4 × 8 = 64.
Which method is faster, prime factorization or the Euclidean algorithm?
For small numbers, prime factorization is easy to do by hand and shows why the answer is right. For large numbers, the Euclidean algorithm is far faster because it only needs division with remainders, no factoring. The calculator shows both.
What if the GCF is 1?
Then the numbers are relatively prime (coprime): they share no factor except 1. For two coprime numbers the LCM is simply their product, for example LCM(8, 15) = 120.
Can I use zero, negative numbers or decimals?
The calculator works with positive whole numbers. A minus sign is ignored, since factors and multiples are usually defined on absolute values. Zero is rejected: every number divides 0, so the LCM with zero isn't useful, and decimals don't have factors in this sense.