GCF and LCM Calculator: Prime Factorization and Euclid's Method
By FindMySum · Last reviewed
A GCF and LCM calculator finds two numbers that sit on either side of any set of whole numbers. The greatest common factor (GCF) is the largest number that divides every number in the set exactly. The least common multiple (LCM) is the smallest positive number that every number in the set divides into exactly. You need the GCF to simplify a fraction or split things into equal groups, and the LCM to find a common denominator or to work out when repeating cycles line up. This calculator takes up to ten positive whole numbers, up to 1,000,000 each, and shows the prime factorization behind both answers.
Prime factorization: the method the calculator uses
Every whole number greater than 1 can be written as a product of prime numbers in exactly one way, apart from the order of the factors. This is the fundamental theorem of arithmetic, and it is what makes the method work. Once each number is broken into primes, the GCF and LCM can be read off directly:
- GCF: take each prime that appears in every number, raised to the lowest power it has in any of them.
- LCM: take every prime that appears in any number, raised to the highest power it has in any of them.
The reasoning is short. A common factor can't contain more copies of a prime than the number with the fewest copies, so the lowest power is as far as the GCF can go. A common multiple must contain at least as many copies as the number with the most, so the highest power is the least the LCM can get away with.
The calculator factors each number by trial division: it divides out 2 as many times as possible, then 3, 5, 7 and the other odd numbers up to the square root of what remains. Whatever is left at the end, if greater than 1, is itself prime.
Worked example: the calculator's defaults
The calculator opens with the numbers 12 and 18.
- Factor each number: 12 = 2 × 2 × 3 = 2² × 3, and 18 = 2 × 3 × 3 = 2 × 3².
- The primes involved are 2 and 3.
- GCF, lowest powers: 2 appears as 2² and 2¹, so take 2¹; 3 appears as 3¹ and 3², so take 3¹. GCF = 2 × 3 = 6.
- LCM, highest powers: take 2² and 3². LCM = 4 × 9 = 36.
A useful check for two numbers: the GCF times the LCM equals the product of the numbers. Here 6 × 36 = 216, and 12 × 18 = 216.
Three numbers
Enter 24, 36 and 60 and the calculator gives:
| Number | Prime factorization |
|---|---|
| 24 | 2³ × 3 |
| 36 | 2² × 3² |
| 60 | 2² × 3 × 5 |
| GCF | 2² × 3 = 12 |
| LCM | 2³ × 3² × 5 = 360 |
The prime 5 appears only in 60, so it is left out of the GCF (its lowest power across the three numbers is zero) but included in the LCM. The product check doesn't apply with three numbers: 12 × 360 is 4,320, while 24 × 36 × 60 is 51,840.
Euclid's algorithm: the shortcut for two numbers
Prime factorization shows its working clearly, but for large numbers there is a faster way to find a GCF that needs no factoring at all. Euclid described it around 300 BCE, and it is still the method most software uses:
- Divide the larger number by the smaller and keep the remainder.
- Replace the larger number with the smaller, and the smaller with the remainder.
- Repeat until the remainder is 0. The last non-zero remainder is the GCF.
For 18 and 12: 18 ÷ 12 leaves 6, then 12 ÷ 6 leaves 0, so the GCF is 6. Then the LCM follows from the product rule: 12 × 18 ÷ 6 = 36. Both methods always agree; the calculator uses prime factors because they let you see why the answer is what it is.
Where you'll use them
- Simplifying fractions. Divide the top and bottom by their GCF: 12/18 becomes 2/3. The fraction calculator does this automatically for every result.
- Common denominators. The LCM of the denominators is the least common denominator, which keeps the numbers small when adding fractions by hand.
- Equal groups. With 24 apples and 36 oranges, the largest number of identical gift bags with nothing left over is the GCF, 12, each with 2 apples and 3 oranges.
- Tiles and grids. The largest square tile that fits a 120 cm by 180 cm area exactly has a side equal to the GCF of 120 and 180.
- Cycles. Schedules, gear teeth and repeating patterns line up again after the LCM of their periods.
Limits
The calculator works with positive whole numbers only. GCF and LCM are defined for integers, so a decimal problem needs scaling first (multiply 1.2 and 1.8 by 10 to get 12 and 18). Each number can be up to 1,000,000 and you can enter up to ten of them. A number with a large prime factor is still quick to factor at that size. To check whether a single number is prime, use the prime number calculator.
More questions
Are GCF, GCD and HCF the same thing?
Yes. Greatest common factor (GCF), greatest common divisor (GCD) and highest common factor (HCF) are three names for the same number. GCF is common in North American schools, HCF in British and Indian textbooks, and GCD in higher mathematics and programming. Least common multiple (LCM) is sometimes written lowest common multiple, with the same meaning.
How do I list all the common factors, not just the greatest?
Every common factor of a set of numbers divides their GCF, and every factor of the GCF is a common factor. So find the GCF and list its factors. For 12 and 18 the GCF is 6, and its factors 1, 2, 3 and 6 are exactly the common factors of 12 and 18.
What is the GCF and LCM of a single number?
Both are the number itself. The largest number that divides 42 is 42, and the smallest positive multiple of 42 is 42. The calculator accepts a single number and returns it as both results, along with its prime factorization, which makes it a quick way to factor a number.
Why can the LCM become so large?
When numbers share few or no prime factors, the LCM has to include all of each one's primes, so it approaches their product. Ten large numbers with no common factors can have an LCM with dozens of digits. The calculator works out the LCM with exact whole-number arithmetic and shows every digit, even beyond the 9,007,199,254,740,991 limit where ordinary computer numbers start rounding.
How do I use the LCM to work out when repeating events line up?
Find the LCM of the intervals. If one bus leaves every 12 minutes and another every 18 minutes, and both leave together at 8:00, they next leave together after LCM(12, 18) = 36 minutes, at 8:36. The same idea gives the length of a repeating rota, or when two gears return to their starting position.
Does the order in which I enter the numbers matter?
No. The GCF and LCM depend only on which numbers are in the set, not on their order, so 18, 12 gives the same results as 12, 18. You can also combine numbers in steps: the GCF of three numbers is the GCF of the first two, combined with the third, and the LCM works the same way.
Sources
This article explains how the calculator works and is general information, not financial, tax, legal or medical advice. Rules change; check the sources above or a qualified professional before you act.