GCD & LCM Calculator (Euclidean Algorithm, Three Numbers)

Run the Euclidean algorithm on two or three integers to find GCD and LCM.

Greatest Common Divisor GCD(a, b, c) 12
Least Common Multiple LCM(a, b, c) 720
Pairwise GCD(a, b) 12
Pairwise LCM(a, b) 720
Inputs
Try:
First positive integer a.
Second positive integer b.
Third positive integer c.
Results & Graph
Greatest Common Divisor GCD(a, b, c)
12
Least Common Multiple LCM(a, b, c)
720
Pairwise GCD(a, b)
12
Pairwise LCM(a, b)
720

Greatest Common Divisor GCD(a, b, c)

Graph 1 • How the inputs feed GCD & LCM
Greatest Common Divisor (GCD) & Least Common Multiple (LCM) Calculator • Custom Domain Schematic (Number Theory) intAintBGCD & LCM Int A: 48 • Int B: 180 GREATEST COMMON DIVISOR GC 12 • Least Common Multiple : 720 • Pairwise GCD(a, b): 12 Eq: LCM(a, b) = |a × b| / GCD(a, b)
Graph 2 • Greatest Common Divisor GCD(a, b, c) as Int A changes (40% to 160% of current)
0 10.56 21.12 4.80 19.20 7.20 28.80 9.60 38.40 12 48 14.40 57.60 16.80 67.20 19.20 76.80
Graph 3 • Int A and Int B together Compares Greatest Common Divisor GCD(a, b, c) when Int B is shifted +25% (solid) vs. −25% (dashed).
0 8.58 17.16 --- Int B @ 75% 8.40 -30% 10.20 -15% 3 +0% 13.80 +15% 15.60 +30%
Summary: For (48, 180, 120), GCD = 12 and Least Common Multiple LCM = 720.
Summary: For (48, 180, 120), GCD = 12 and Least Common Multiple LCM = 720.
Interactive chart & math engine powered by CalculatorGraph

Formula: GCD & LCM Mathematical Identity

LCM(a, b) = |a × b| / GCD(a, b)
LCM(a, b) = |a × b| / GCD(a, b)
  • intA: Int A (numeric parameter)
  • intB: Int B (numeric parameter)
  • intC: Int C (numeric parameter)

Frequently Asked Questions

What mathematical formula does the Greatest Common Divisor (GCD) & Least Common Multiple (LCM) Calculator use?

It directly evaluates LCM(a, b) = |a × b| / GCD(a, b) in double-precision floating-point arithmetic and updates all supporting invariants and graphs live.

Why does the order of the three numbers not matter?

GCD and LCM are both commutative and associative, so any grouping gives the same answer. GCD(48, 180, 120) is 12 whether you pair 48 with 180 first or 180 with 120 first. Only the pairwise lines change with order, because they always refer to the first two boxes, so put the pair you care about in A and B.

Is there a quick way to tell if two numbers are coprime?

Run them through Euclid's steps; if the last nonzero remainder is 1, they are coprime. A shortcut catches many cases: if both are even, or both end in 0 or 5, they share a factor. Two different primes are always coprime, which is why 29 and 180 give a GCD of 1 on this page.

Can the GCD ever be larger than the smallest input?

No. The GCD has to divide every input, and a number cannot divide a smaller positive number. So the GCD is at most the smallest absolute value among your inputs, and it equals it only when the smallest number divides all the others. With 48, 180 and 120, the bound is 48 and the true answer is 12.

Can the LCM be smaller than the largest input?

No. A common multiple of 180 has to be at least 180, and the LCM equals the largest input exactly when the other inputs already divide it. In the 72 scenario, 72 and 120 both divide 360, but not 180, so the LCM is 360 rather than 180, and with the default 48, 180 and 120, it climbs to 720.

How many steps does Euclid's algorithm take?

Very few. Each pair of steps at least halves the smaller number, so the count grows with the number of digits, not with the size of the numbers. The default pair 180 and 48 finishes in three divisions. Even integers hundreds of digits long finish in a few hundred steps, which is why the method is used in cryptographic software.

What is the difference between the GCD and the HCF?

None. Highest common factor (HCF) and greatest common divisor (GCD) are two names for the same number, the largest integer that divides every input with no remainder. Textbooks in some countries prefer HCF, and some call the LCM the lowest common multiple. The page's answer of 12 for the default trio is the HCF as well.

How do I find the GCD of more than three numbers?

Chain it. Take the GCD of the first two, then the GCD of that result with the third, then with the fourth, and so on. You can use this calculator for the first three, then enter the result with the next number in box A and repeat. The LCM chains the same way, one number at a time.

Why do I get a GCD of 1 for numbers that look related?

Looking related is not the same as sharing a factor. 6, 10 and 15 each share a factor with each other in pairs, yet no single number above 1 divides all three, so their GCD is 1 while their LCM is 30. Check the pairwise line: a pairwise GCD above 1 with a three-number GCD of 1 means exactly this.

Can I use this for polynomials or fractions?

Not directly. The boxes take integers. For fractions, scale them to whole numbers with a common power of ten or a common denominator, find the GCD, then scale back. Polynomials have their own Euclidean algorithm using polynomial division, which this page does not perform, although the idea of repeated remainders is identical.

Why does the LCM of 29, 180 and 120 equal 29 times 360?

Because 29 is prime and shares nothing with the other two. The LCM of 180 and 120 is 360. Bringing in a number coprime to 360 multiplies the LCM by that number in full, so the result is 10,440. Any time a new input is coprime to the running LCM, expect that kind of jump.

Does the LCM always grow when I add a third number?

It never shrinks, but it does not always grow. If the new number already divides the LCM of the first two, the LCM stays put. With 48 and 180 the LCM is 720, and adding 120 leaves it at 720 because 120 divides it six times. Adding 29 instead multiplies it, since 29 shares no factor with the existing LCM.

Running Euclid's steps on 48, 180 and 120 by hand

Out of the box the calculator holds 48, 180 and 120 and reports a GCD of 12 and an LCM of 720. Both are easy to reproduce with a pencil, and doing it once makes the result lines much easier to trust.

The Euclidean algorithm replaces the larger number with the remainder after dividing by the smaller, and repeats until the remainder is zero. Start with 180 and 48. Forty-eight goes into 180 three times with 36 left over. Now work with 48 and 36: 36 goes in once, leaving 12. Then 36 and 12: 12 goes in exactly three times, remainder zero. The last nonzero remainder, 12, is GCD(48, 180).

That is the 'Pairwise GCD(a, b): 12' line. To bring in the third number, run the same process on 12 and 120: since 120 is exactly ten twelves, the remainder is zero at once and the three-number GCD stays 12.

Notice how few steps it took. Euclid's method does not need you to find factors, which is why it stays fast even for very large integers where factoring would be slow.

Checking 12 and 720 with prime factors

A second route gives the same answer and shows why. Write each number as a product of primes. 48 is 2 × 2 × 2 × 2 × 3. 180 is 2 × 2 × 3 × 3 × 5. 120 is 2 × 2 × 2 × 3 × 5.

For the GCD, take each prime at the smallest power that appears in all three. Two appears at least twice in every number, three at least once, and five is missing from 48. So the GCD is 2 × 2 × 3, which is 12.

For the LCM, take each prime at the largest power that appears anywhere: four twos from 48, two threes from 180, one five. That gives 16 × 9 × 5, which is 720. Every one of the three inputs divides 720 exactly, and no smaller positive number has that property.

Factoring is handy for checking small inputs by hand, and it makes patterns visible: the GCD collects what the numbers share, the LCM collects everything any of them needs. For large inputs, trust Euclid instead.

Three numbers are handled in pairs: the 72 scenario

The calculator shows pairwise lines for a and b next to the three-number results. That is because GCD and LCM of three numbers are built up one pair at a time. GCD(a, b, c) is GCD(GCD(a, b), c), and the LCM works the same way.

Changing the first input to 72 shows why the pairwise lines matter. GCD(72, 180) jumps to 36, because 72 and 180 share two twos and two threes. But 120 has only one three, so folding it in brings the three-number GCD back down to 12. The LCM goes the other way: LCM(72, 180) is 360, and since 120 already divides 360, the three-number LCM stays at 360, half the default 720.

A common mistake is to use the two-number shortcut on three numbers. For a pair, GCD times LCM equals the product of the pair. For three numbers it does not: 48 times 180 times 120, divided by 12, is far larger than 720. Always chain the pairs.

What a prime like 29 does to both answers

The page's lower scenario swaps 48 for 29. The GCD drops to 1, and the LCM jumps to 10,440. Both are what you would expect from a prime.

A prime shares no factor with any number it does not divide, and 29 divides neither 180 nor 120, so GCD(29, 180) is 1, and the three-number GCD is 1 as well. Numbers with a GCD of 1 are called coprime.

For coprime numbers the LCM is just the product. LCM(29, 180) is 29 × 180, which is 5,220, matching the pairwise line. The LCM of 180 and 120 on their own is 360, so the full answer is 29 × 360, which is 10,440.

This is a useful sanity test when you get a surprisingly large LCM: check whether one input is prime or coprime to the others. If it is, a big jump is correct, not a glitch.

Negatives, zero and decimal entries

Negative inputs are fine. The divisors of minus 48 are the same as the divisors of 48, so the calculator works with absolute values. Entering minus 48, 180 and 120 returns a GCD of 12 and an LCM of 720, exactly the same as the default, and by convention both results are reported as positive.

Zero is allowed too, and it follows the textbook rules. Every integer divides zero, so GCD(0, n) equals n. Put 0 in the first box with 180 and 120 and the page returns a GCD of 60, the same as GCD(180, 120), while the pairwise GCD(0, 180) line reads 180; the LCM of any set containing zero is 0, since zero is the only common multiple, and the page shows 0 for both LCM lines. With 48, 180 and 0 the GCD stays 12 and the LCM becomes 0. Only all three boxes at zero is rejected, because GCD(0, 0, 0) has no meaningful value.

Decimals are rejected with a message asking for whole numbers, rather than being rounded behind your back. If you need the GCD of 1.2 and 4.5, multiply both by 10 to get 12 and 45, find the GCD (3), then divide back by 10 to get 0.3. The same scaling trick works for any pair of terminating decimals.

Getting a two-number answer from a three-box form

There are three boxes, but plenty of problems only involve two numbers. The pairwise lines already give GCD(a, b) and LCM(a, b), so for a quick pair you can ignore the third box and read those.

If you want the headline result to match, set the third box equal to the first or second number. GCD(48, 180, 48) is the same as GCD(48, 180), which is 12, and the LCM is unchanged at 720, because repeating a number adds no new factors.

Do not set the third box to 1 for this purpose. One divides everything, so it leaves the LCM alone, but it forces the three-number GCD to 1. That is a correct answer to a different question, and it is easy to misread.

Bézout coefficients for 48 and 180, found by back-substitution

Bézout's identity says the GCD of two integers can always be written as a whole-number combination of them: there are integers x and y with 48x plus 180y equal to 12. Finding x and y means running Euclid's steps backwards.

From the steps above, 12 is 48 minus 36. And 36 is 180 minus three 48s. Substitute: 12 is 48 minus (180 minus 3 × 48), which is 4 × 48 minus 180, so x is 4 and y is minus 1. Check it: four 48s come to 12 more than 180, as required.

The calculator's result lines report the GCD and LCM rather than these coefficients, so use the back-substitution above when you need them. They matter in modular arithmetic: because 4 × 48 leaves remainder 12 after dividing by 180, they are the first step towards solving equations like 48x leaving a given remainder modulo 180, and they underpin modular inverses in cryptography.

Fractions, schedules and tiles: where 12 and 720 get used

Simplifying a fraction is a GCD job. To reduce 48/180, divide top and bottom by 12 to get 4/15. For 120/180 the GCD is 60, which gives 2/3.

Adding fractions is an LCM job. To add 1/48, 1/180 and 1/120, the smallest common denominator is 720, the same LCM the page shows. Using it instead of multiplying all three denominators keeps the numbers small and the final fraction close to lowest terms.

Repeating events coincide at the LCM. If three machines need servicing every 48, 180 and 120 minutes and all were done together at 6 am, they next line up after 720 minutes, so at 6 pm. Tiling uses the GCD: a 48 by 180 board cuts into equal squares with no waste only if the side divides both, and the biggest such square is 12 by 12.

One computing tip from the identity on the page: when working out LCM(a, b) as a × b divided by GCD, divide first. 48 divided by 12 is 4, and 4 × 180 is 720. Multiplying first creates a much larger intermediate number, which can overflow fixed-size integers in code.

Mistakes that give a wrong GCD or LCM

Most wrong answers come from a handful of slips rather than from the method itself. The first is stopping Euclid's steps one row early and reporting the last divisor instead of the last nonzero remainder. With 180 and 48 the rows end 36 = 3 × 12 + 0, and the answer is 12, not 36.

The second is mixing up which result a word problem wants. If the question asks for the largest equal group, the biggest tile, or a way to simplify, it wants the GCD. If it asks when things next happen together, or for the smallest amount every quantity divides into, it wants the LCM. With the default inputs those are 12 and 720, and confusing them is off by a factor of sixty.

The third is typing a value with a unit or a decimal point, such as 12.5 or 48 cm, when the problem needs whole numbers. The page will refuse 12.5 outright. Convert everything to the same whole unit first, for example minutes rather than a mix of hours and minutes, then enter plain integers.