Tools · Math & Statistics

GCF and LCM Calculator

The greatest common factor and least common multiple of any list of whole numbers — with the prime factorisation of each one, so you can watch both answers being read off the same table rather than taking two numbers on trust.

Shows the factorisation behind both answersHow it worksInputs stay on this device
Your inputs

Factors and multiples

Two to twenty whole numbers, each from 1 through 1,000,000,000. Commas, spaces, tabs and new lines all separate — so a spreadsheet column pastes straight in. Because a comma separates, type 1234, not 1,234.

Your inputs are calculated locally and are not stored.
Greatest common factor6

All 3 numbers divide by 6, and the smallest number they all divide into is 72 — their least common multiple.

Least common multiple
72
GCF in prime factors
2 × 3
LCM in prime factors
2³ × 3²
How many numbers
3
Coprime
No
Every number in prime factors, with the GCF and the LCM read straight off them
NumberPrime factorisationNotes
122² × 3
182 × 3²
242³ × 3
GCF 62 × 3Smallest exponent of each prime shared by all
LCM 722³ × 3²Largest exponent of every prime that appears
Formula & methodology

One table, two answers: minimum and maximum exponent

Every whole number above 1 breaks into primes in exactly one way. Write the numbers that way and both answers stop being facts to memorise — they are two different readings of the same table.

12 = 2² × 3  •  18 = 2 × 3²  •  24 = 2³ × 3
GCF
The smallest exponent of each prime that appears in every number: 2¹ × 3¹ = 6
LCM
The largest exponent of every prime that appears anywhere: 2³ × 3² = 72
Why
A common factor cannot use more of a prime than the stingiest number has; a common multiple must carry as much of each prime as the greediest number needs

Why the arithmetic is still done by Euclid

Reading the answer off the factorisations is how it is understood. It is not how it should be computed: factoring gets slower as numbers grow, while Euclid's algorithm — replace the larger number by the remainder of dividing it by the smaller, and repeat until nothing is left over — finds a greatest common factor in a number of steps proportional to the digits, not the value. So the figures on this page are folded across your list with Euclid, and the factorisations are worked out alongside for display. That the two routes agree is checked by a unit test.

Why the division comes before the multiplication

The identity is lcm(a, b) = a × b ÷ gcd(a, b), but evaluating it in that order forms a × b first — for two nine-digit inputs, an eighteen-digit number, past the point where a browser counts integers exactly, even when the final answer would have fitted comfortably. Dividing first, (a ÷ gcd) × b, never forms anything larger than the answer itself. When even the answer will not fit, the calculator says so instead of quietly returning an approximation — an approximate multiple is not a multiple.

Worked example

12, 18 and 24, factor by factor

Break each one down: 12 = 2 × 2 × 3, which is 2² × 3. 18 = 2 × 3 × 3, which is 2 × 3². 24 = 2 × 2 × 2 × 3, which is 2³ × 3.

For the GCF, look at each prime and take the smallest exponent it reaches across all three. The prime 2 appears with exponents 2, 1 and 3 — the smallest is 1. The prime 3 appears with exponents 1, 2 and 1 — again the smallest is 1. So the GCF is 2¹ × 3¹ = 6. It cannot be more: 18 only has one factor of 2 to give.

For the LCM, take the largest exponent instead. The prime 2 reaches 3, in 24. The prime 3 reaches 2, in 18. So the LCM is 2³ × 3² = 8 × 9 = 72. It cannot be less: anything divisible by 24 needs three factors of 2, and anything divisible by 18 needs two factors of 3.

Now the schedule version. Two buses leave a stop together, one every 12 minutes, one every 18. The first goes at 12, 24, 36, 48; the second at 18, 36, 54. They coincide at 36 minutes — the LCM of 12 and 18 — and then every 36 minutes after that. Type 12, 18 into the box above and the LCM line answers the question directly.

Where it is used

What each one is actually for

  • GCF — reducing a fraction. Divide numerator and denominator by their GCF and you are in lowest terms in one step. 18/24 has a GCF of 6, so it is 3/4. Anything smaller than the GCF leaves work behind.
  • GCF — cutting without waste. Three lengths of trim at 12, 18 and 24 inches, all to be cut into equal pieces with nothing left over: the longest such piece is 6 inches. Same arithmetic for tiling a rectangle with the largest square, or packing mixed items into identical boxes.
  • LCM — when two cycles coincide. Buses, shift rotas, maintenance intervals, backup jobs, gear teeth returning to the same alignment. Two things repeating every a and b meet again after lcm(a, b).
  • LCM — adding fractions. The lowest common denominator of 1/12 and 1/18 is the LCM of 12 and 18, which is 36 — so the sum is 3/36 + 2/36 = 5/36. Using 216 instead works too, but leaves you reducing afterwards.
Assumptions

What this calculator assumes

  • Inputs are whole numbers from 1 through 1,000,000,000, and at least two of them. Factors and multiples are defined on integers, and a common factor needs something to be common to.
  • Zero and negative numbers are excluded. Every number divides zero, so including it makes the LCM 0 and stops the GCF discriminating; a minus sign carries no information about divisibility, so gcd(−12, 18) is only gcd(12, 18) with a convention attached.
  • 1 is shown with no prime factors, because it has none — it is the empty product. It is not prime, and a list containing it is always coprime.
  • The least common multiple is refused past 9,007,199,254,740,991 — the largest integer a browser counts exactly. Twenty coprime nine-digit numbers blow past that easily, and a multiple that is only approximately right is not a multiple of anything.
  • Factorisation is by trial division up to the square root, which is exact and fast at this size — the worst case, a nine-digit prime, is some fifteen thousand divisions.
  • Every figure here is an exact integer. Nothing is rounded, because nothing has a decimal to lose.
Common questions

GCF and LCM FAQ

What is the difference between the GCF and the LCM?

The greatest common factor is the largest number that divides into all of them; the least common multiple is the smallest number they all divide into. Factors are smaller than or equal to the numbers, multiples are larger than or equal to them, and the two answers pull in opposite directions from the same set. For 12, 18 and 24 the GCF is 6 — the biggest thing all three contain — and the LCM is 72, the first place all three land together.

Two buses leave every 12 and 18 minutes. When do they leave together again?

After 36 minutes, which is the least common multiple of 12 and 18. The first bus leaves at 12, 24, 36, 48; the second at 18, 36, 54. The earliest time on both lists is 36. This is what the LCM is for in practice: anything that repeats on a fixed cycle — bus timetables, shift rotas, maintenance intervals, traffic lights, planetary orbits — coincides again after the LCM of the cycle lengths, and not before.

How does the GCF reduce a fraction?

Divide the top and the bottom by their greatest common factor and you land in lowest terms in one step. For 18/24 the GCF is 6, so 18 ÷ 6 = 3 and 24 ÷ 6 = 4, giving 3/4. Dividing by anything smaller than the GCF leaves the fraction still reducible — dividing 18/24 by 2 gives 9/12, which is not finished. That is the whole reason the GCF is defined as the greatest one.

What does coprime mean? Do the numbers have to be prime?

Coprime means the GCF is 1 — the numbers share no factor above 1. Neither of them has to be prime for that to hold. 8 and 9 are coprime because 8 is 2³ and 9 is 3², and they have no prime in common, even though 8 and 9 are both composite. When a set is coprime the least common multiple is simply the product, because there is nothing shared to divide out.

Can I find the GCF of more than two numbers?

Yes, and both operations fold across a list: the GCF of three numbers is the GCF of the first two taken with the third, and the same works for the LCM. The calculator above takes up to twenty. The factorisation table makes the fold visible — every prime that survives into the GCF is one that appears in every single column.

Why is 1 shown as having no prime factors?

Because it genuinely has none. Every whole number above 1 is a product of primes in exactly one way, and 1 is the empty product — nothing multiplied together. That is also why 1 is not counted as prime: if it were, factorisations would stop being unique, since you could staple on any number of 1s. Its practical effect here is that any list containing 1 has a GCF of 1 and is therefore coprime.

Primary sources

Sources and review notes

  1. NIST Digital Library of Mathematical Functions §27.2 — the canonical prime factorisation, the fundamental theorem of arithmetic that makes it unique, and the reason the factorisation table on this page has exactly one right answer per number
  2. NIST Digital Library of Mathematical Functions §27.1 — the standard notation for the greatest common divisor and the least common multiple of a set of integers

The Euclidean algorithm used here is Propositions 1 and 2 of Book VII of Euclid's Elements, and has not needed revising since. There is no data behind this page to go stale — only arithmetic, which is why the engine is a pure function under unit test, including a case that fails if Euclid and the factorisations ever disagree.