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
6
72
The working
As prime factors
| Number | = |
|---|---|
| 12 | 2² × 3 |
| 18 | 2 × 3² |
| 24 | 2³ × 3 |
| GCD | 2 × 3 |
| LCM | 2³ × 3² |
The GCD takes the smallest power of each prime; the LCM takes the largest. That is the whole method, in one table.
Venn diagram
GCD = the middle = 2 × 3 = 6
LCM = everything = 2³ × 3² = 72
Each circle holds one number’s prime factors. The part every circle shares multiplies to the GCD; everything in the diagram multiplied together is the LCM.
The ladder (division method)
| 2 | 12 | 18 | 24 |
| 2 | 6 | 9 | 12 |
| 2 | 3 | 9 | 6 |
| 3 | 3 | 9 | 3 |
| 3 | 1 | 3 | 1 |
| 1 | 1 | 1 |
LCM = 2 × 2 × 2 × 3 × 3 = 72
GCD = 2 × 3 = 6
Divide by a prime that goes into at least one number, bring the others down unchanged, and repeat until every number on the bottom row is one. The primes down the left multiply to the LCM; the ones in bold went into every number, and multiply to the GCD.
Shown for two numbers at a time; for a longer list the factor table above is the method.
From the GCD to the LCM
LCM(12, 18) = 12 × 18 ÷ GCD(12, 18) = 216 ÷ 6 = 36
LCM(36, 24) = 36 × 24 ÷ GCD(36, 24) = 864 ÷ 12 = 72
For any two numbers, GCD × LCM = a × b, so LCM(a, b) = a × b ÷ GCD(a, b). For more numbers it is applied one number at a time.
Listing multiples
12: 12, 24, 36, 48, 60, 72
18: 18, 36, 54, 72
24: 24, 48, 72
List each number’s multiples until one appears in every list — the first that does, in bold, is the LCM.
Divisors they all share
12: 1, 2, 3, 4, 6, 12
18: 1, 2, 3, 6, 9, 18
24: 1, 2, 3, 4, 6, 8, 12, 24
Each number’s own divisors; the ones in bold divide every number, and the largest of those is the GCD.
1, 2, 3, 6
These are exactly the divisors of the GCD — the last one is the answer above.
Word problems
Buses. Three buses leave the station together. One comes back every 18 minutes, one every 12 and one every 24. How long until all three are back at the same time?
Ribbons. Two ribbons, 84 cm and 126 cm long, are cut into pieces all the same length with nothing left over. How long can the pieces be at most?
Teams. 24 girls and 36 boys are split into teams, each with the same number of girls and the same number of boys. What is the most teams there can be?
Sausages and buns. Sausages come in packs of 10 and buns in packs of 8. What is the fewest of each you can buy and have exactly as many sausages as buns?
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 number is skipped, so a slightly messy paste still gives a clean answer.
The working behind the answers
Underneath the two answers the page shows how they were reached — every method by default, while “Show the working” narrows it to one method or to just the answers. 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. Two more routes are printed for a pair: Euclid by subtraction, taking the smaller number from the larger until the two are equal — the form a textbook often draws first — and the binary (Stein's) algorithm, which only halves and subtracts. 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. When the GCD is 1 a line says the numbers are coprime, and for three or more it says whether every pair is too, or names a pair that is not.
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 would freeze 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, the way a list of three or more is done by hand, shows up to 50 of them at once — 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.
Does it list multiples and divisors, and does it take decimals?
Yes. Alongside Euclid's steps it lists the multiples, each number's divisors with the shared ones marked, and the ladder (division) method, and it uses LCM(a, b) = a × b ÷ GCD(a, b). Decimals and fractions are answered exactly too.
Can I pick one method, see a Venn diagram, share the result, or try a word problem?
Yes. “Show the working” picks every method (the default), none — just the answers — or one of them, and Copy link carries that choice with the numbers; a list too long for an address stays on the page, which says so instead of offering a link. For two or three whole numbers, the Venn diagram puts each number's prime factors in its own circle: the part every circle shares multiplies to the GCD, and everything in the diagram to the LCM. Under the working, the Word problems — buses, ribbons, teams, sausages and buns — each have a “Work it out” button that loads their numbers into the box and shows the answer sentence.
Does it say when numbers are coprime, and can it show other GCD methods?
Yes. When the GCD is 1 a line says the numbers are coprime — they share no prime factor, though neither has to be prime — and with three or more it adds whether every pair is coprime or names the first pair that is not. For two numbers, “Show the working” also offers Euclid by subtraction, taking the smaller from the larger until the two are equal, and the binary GCD (Stein's algorithm), which uses only halving and subtraction; each stops writing lines at a limit and says so.