GCD & LCM Calculator

Find the GCD and LCM of any list of integers and see the working — the prime factor table, the Euclidean algorithm step by step, and every shared divisor.

Numbers used: 12, 18, 24

GCD (greatest common divisor)
6
LCM (least common multiple)
72

The working

As prime factors

Number=
122² × 3
182 × 3²
242³ × 3
GCD2 × 3
LCM2³ × 3²

The GCD takes the smallest power of each prime; the LCM takes the largest. That is the whole method, in one table.

Shown for two numbers at a time; for a longer list the factor table above is the method.

Divisors they all share

1, 2, 3, 6

These are exactly the divisors of the GCD — the last one is the answer above.

🔒 Calculated in your browser — nothing is uploaded.

What this calculator does

Type two or more integers separated by commas or spaces and it shows the greatest common divisor and the least common multiple straight away. The GCD is the largest whole number that divides every number in the list with nothing left over; the LCM is the smallest positive number every one of them divides into. Minus signs are ignored, and anything that is not a whole number is skipped, so a slightly messy paste still gives a clean answer.

And the working, because that is what the marks are for

Underneath the two answers the page shows how they were reached, three ways. The prime factor table writes each number as its primes — 12 = 2² × 3, 18 = 2 × 3² — and then shows the GCD taking the smallest power of each prime and the LCM taking the largest. That one table is the whole method, and it is shown for up to 50 numbers at a time — past that the GCD and LCM above are still exact, and the page says why the table is missing. For a pair, the Euclidean algorithm is printed line by line: 48 = 2 × 18 + 12, then 18 = 1 × 12 + 6, then 12 = 2 × 6 + 0, and the last divisor is the answer. Last comes every divisor the numbers share, which is exactly the list of divisors of the GCD — so the final entry is always the answer above it.

Exact, however large the answer

The LCM of a long list grows fast, and past about nine quadrillion an ordinary number stops being able to hold it exactly. The LCM here is accumulated in big integers instead, so it stays exact rather than becoming a plausible round number. The working has its own limits, because the factoring and the divisor sweep are both trial division: a number beyond about a trillion is left out of the factor table, the table is built for at most 50 numbers at once, and the shared-divisor list is skipped when the GCD itself is above a trillion. Each of those is named on the page rather than quietly dropping the section — without them, a megabyte of pasted numbers froze the tab for more than half a minute on every keystroke.

Frequently asked questions

What is the difference between GCD and LCM?

The GCD is the biggest number that goes into all of them; the LCM is the smallest number they all go into. For 12 and 18 the GCD is 6 and the LCM is 36. GCD is what you reduce a fraction by; LCM is the common denominator you add fractions over.

Can I see how the answer was worked out?

Yes — that is most of the page. The prime factor table shows each number broken into primes with the GCD and LCM rows read off it, the Euclidean algorithm is printed step by step for a pair of numbers, and the divisors the numbers share are listed in full, unless there are more than 200 of them or the GCD is above a trillion — which the page says instead of going quiet.

How does the Euclidean algorithm work?

Divide the larger number by the smaller and keep the remainder. Then divide the number you just divided by, by that remainder. Repeat until the remainder is 0; the last number you divided by is the GCD. The page prints each of those lines for you.

Can I use more than two numbers?

Yes, as many as you like — the GCD and LCM are built up across the whole list. The prime factor table shows up to 50 of them at once, which is how a list of three or more is done by hand and already more rows than a page can usefully show; above that the two answers stay and the table says why it is not there. The Euclidean steps are shown for two numbers at a time, since that is the form the algorithm takes.

Are my numbers uploaded?

No. Everything is calculated in your browser with JavaScript. Nothing you type is sent anywhere, logged or stored.