GCF and LCM Calculator
Find the GCF and LCM of two or more whole numbers, with the prime factorization of every number, the GCF and the LCM.
What is a GCF and LCM calculator?
The greatest common factor (GCF) of a list of whole numbers is the largest number that divides every one of them with no remainder. It is also called the greatest common divisor (GCD); the two names mean the same thing. The least common multiple (LCM) is the smallest positive number that every number in the list divides into evenly. For 24, 36 and 60, the GCF is 12 and the LCM is 360.
This GCF and LCM calculator takes two or more whole numbers, separated by commas, spaces or semicolons, and returns the Greatest common factor (GCF / GCD), the Least common multiple (LCM), the Prime factorizations of each number and of the GCF and LCM, and the Numbers used. That last line matters: anything the calculator cannot use, such as 0, a decimal like 2.5 or a word, is listed as ignored rather than quietly rounded or changed. A minus sign is dropped, so −12 is treated as 12.
The calculator works in exact whole-number arithmetic, so even an LCM with dozens of digits is exact, not rounded. Prime factorizations are shown for numbers up to one trillion (1,000,000,000,000); larger numbers still get an exact GCF and LCM.
In the Common Core State Standards, students find factor pairs and identify primes for numbers from 1 to 100 in grade 4 (4.OA.B.4). In grade 6 (6.NS.B.4) they find the GCF of two whole numbers up to 100 and the LCM of two whole numbers up to 12.
Formula
There are two standard ways to find a GCF and an LCM. They always give the same answer.
Method 1: prime factorization
Write each number as a product of primes. Then:
- GCF = the product of the primes that appear in every number, each raised to its lowest power.
- LCM = the product of every prime that appears in any of the numbers, each raised to its highest power.
Method 2: the Euclidean algorithm (what the calculator uses)
For two numbers a and b, divide the larger by the smaller and keep the remainder:
gcd(a, b) = gcd(b, a mod b), repeated until the remainder is 0. The last nonzero remainder is the GCF.
The LCM then follows from the GCF:
lcm(a, b) = a ÷ gcd(a, b) × b
Dividing before multiplying keeps the numbers small. For a list of three or more numbers, the calculator works through the list one number at a time: gcd(a, b, c) = gcd(gcd(a, b), c), and the same for the LCM. For 24, 36 and 60, gcd(24, 36) = 12 and gcd(12, 60) = 12, while lcm(24, 36) = 72 and lcm(72, 60) = 360.
A useful check, and its limit
For two numbers, GCF × LCM always equals the product of the numbers. For 84 and 126: 42 × 252 = 10,584 and 84 × 126 = 10,584. This does not work for three or more numbers. For 24, 36 and 60, GCF × LCM = 12 × 360 = 4,320, but 24 × 36 × 60 = 51,840.
The prime factorizations are found by trial division (dividing by 2, then by odd numbers), which is fast for numbers up to one trillion. Above that, the Prime factorizations line says "too large to factor here", but the Euclidean algorithm still gives the exact GCF and LCM. For a slower, step-by-step walk through factor trees, see prime factorization made easy.
Worked example
Example 1: GCF and LCM of 24, 36 and 60
Enter 24, 36, 60. The Prime factorizations line reads:
24 = 2³ × 3; 36 = 2² × 3²; 60 = 2² × 3 × 5; GCF 12 = 2² × 3; LCM 360 = 2³ × 3² × 5
| Prime | 24 | 36 | 60 | Lowest power (GCF) | Highest power (LCM) |
|---|---|---|---|---|---|
| 2 | 2³ | 2² | 2² | 2² | 2³ |
| 3 | 3 | 3² | 3 | 3 | 3² |
| 5 | none | none | 5 | none | 5 |
GCF = 2² × 3 = 4 × 3 = 12. LCM = 2³ × 3² × 5 = 8 × 9 × 5 = 360. The prime 5 is left out of the GCF because 24 and 36 do not contain it.
Example 2: equal groups with the Euclidean algorithm
A teacher has 84 pencils and 126 erasers and wants to make identical supply kits with nothing left over. The largest number of kits is the GCF of 84 and 126.
- 126 = 1 × 84 + 42, so the remainder is 42.
- 84 = 2 × 42 + 0. The remainder is 0, so the last nonzero remainder, 42, is the GCF.
- Each of the 42 kits gets 84 ÷ 42 = 2 pencils and 126 ÷ 42 = 3 erasers.
The calculator shows a GCF of 42 and an LCM of 84 ÷ 42 × 126 = 252, with 84 = 2² × 3 × 7 and 126 = 2 × 3² × 7.
Example 3: when things line up again (LCM)
Suppose hot dogs come in packs of 10 and buns in packs of 8. To buy exactly the same number of each, you need the smallest common multiple of 10 and 8. Enter 10, 8: the LCM is 40 (10 = 2 × 5 and 8 = 2³, so the LCM is 2³ × 5). That is 40 ÷ 10 = 4 packs of hot dogs and 40 ÷ 8 = 5 packs of buns. The same idea answers "two buses leave every 12 and 18 minutes; when do they next leave together?" The LCM of 12 and 18 is 36, so 36 minutes later.
Example 4: a large LCM and an ignored entry
Enter the numbers 1 through 20. The GCF is 1 and the LCM is 232792560 = 2⁴ × 3² × 5 × 7 × 11 × 13 × 17 × 19. Extend the list to 30 and the LCM, 2329089562800, is above one trillion, so its factorization reads "too large to factor here" while the LCM itself stays exact. Type 8 2.5 12 and Numbers used reads 8, 12 (ignored: 2.5 — whole numbers other than 0 only); the GCF of 4 and LCM of 24 are for 8 and 12 only.
How to use this calculator
- Type two or more whole numbers in the box, separated by commas, spaces or semicolons, for example 24, 36, 60.
- Leave out thousands separators: type 1000, not 1,000, because the comma is read as a separator between two numbers.
- Read the Greatest common factor (GCF / GCD) and the Least common multiple (LCM).
- Use Prime factorizations to see where each answer comes from, or to check your own factor tree.
- Check Numbers used to make sure every entry was counted. Anything shown as ignored was left out of both answers.
When to use the GCF and when to use the LCM
- Simplifying a fraction: GCF. The GCF of 18 and 24 is 6, so 18/24 = 3/4.
- Splitting things into the largest equal groups: GCF, as in Example 2.
- Adding fractions: LCM. The least common denominator of 1/4 and 1/6 is the LCM of 4 and 6, which is 12.
- Repeating events or packs that must match up: LCM, as in Example 3.
Common mistakes
- Multiplying to get the LCM. 4 × 6 = 24 is a common multiple, but the LCM is 12. The product is the LCM only when the GCF is 1.
- Typing 1,000 with a comma. The calculator reads 1 and 000, uses 1, and lists 000 as ignored.
- Using GCF × LCM = product for three numbers. It only holds for two.
- Mixing up factors and multiples. A factor of 12 divides into 12 (1, 2, 3, 4, 6, 12); a multiple of 12 is 12 times something (12, 24, 36, and so on).
Related help: GCF vs LCM and when to use each, adding fractions with different denominators, the fraction calculator and the ratio calculator, which reduces a ratio to lowest terms using the same GCF idea.
Sources
Frequently asked questions
Are GCF and GCD the same thing?
Yes. Greatest common factor (GCF) and greatest common divisor (GCD) are two names for the same number, which is why the result is labeled Greatest common factor (GCF / GCD). A factor and a divisor of a whole number are the same thing: a number that divides it with no remainder.
What does it mean when the GCF is 1?
The numbers share no prime factor, so they are called relatively prime (or coprime). For two such numbers the LCM is simply their product: 17 and 19 give a GCF of 1 and an LCM of 323 = 17 × 19. A list can have a GCF of 1 even when some pairs share a factor. For 6, 10 and 15, each pair has a common factor (2, 3 or 5), but no prime divides all three, so the GCF is 1 and the LCM is 30.
Why were some of my numbers ignored?
The calculator only uses whole numbers other than 0, written with digits and an optional minus sign. Anything else is listed in Numbers used after "ignored", so you can see exactly what was left out. That includes decimals (2.5, and also 12.0), a leading plus sign (+12), fractions such as 3/4, words, and 0. Retype the entry as a plain whole number, for example 12 instead of 12.0, and the results update.
How does it handle negative numbers?
It drops the minus sign and uses the absolute value, because factors and multiples are about size, and the GCF and LCM are given as positive numbers. Entering −12, 18 gives the same result as 12, 18: a GCF of 6 and an LCM of 36, and Numbers used shows 12, 18.
Why is 0 not allowed?
Every whole number divides 0, so 0 adds nothing to a GCF: the GCF of 12 and 0 would just be 12. For the LCM, the only multiple of 0 is 0 itself, so there is no smallest positive common multiple. Rather than return a misleading answer, the calculator lists 0 as ignored and works with the other numbers. If 0 is the only entry, there is no result.
How large can the numbers be?
The GCF and LCM are calculated with exact whole-number arithmetic, so there is no practical size limit and no rounding. For example, 9007199254740993 (that is, 2⁵³ + 1) and 3 give an exact GCF of 3 and LCM of 9007199254740993, a number that the standard floating-point numbers used by JavaScript cannot store exactly. Prime factorizations stop at one trillion: above that the line reads "too large to factor here".
Can I find the GCF of decimals or fractions?
Not directly; the calculator accepts whole numbers only. For decimals with the same number of decimal places, scale them to whole numbers first. For 1.2 and 1.8, enter 12 and 18 to get a GCF of 6, then scale back: 0.6 divides 1.2 exactly 2 times and 1.8 exactly 3 times. To reduce a decimal ratio such as 1.5 : 2.25, the ratio calculator does the scaling for you.
Is GCF × LCM always equal to the product of the numbers?
Only for two numbers. For 84 and 126, 42 × 252 = 10,584, the same as 84 × 126. For three or more numbers it fails: 24, 36 and 60 have GCF × LCM = 4,320, but their product is 51,840.