GCD and LCM Calculator

GCD and LCM Calculator

Find the greatest common divisor and least common multiple of two whole numbers with the Euclidean algorithm written out as substitution steps.

Quick Answergcd(a, b) is the largest integer that divides both numbers. Repeat a = q·b + r until the remainder is 0; the last non-zero remainder is the gcd. Then lcm(a, b) = |a·b| / gcd(a, b). For 12 and 18, gcd = 6 and lcm = 36.
gcd(12, 18) = 6, lcm = 36





Enter two whole numbers. Negatives are allowed; the gcd is reported as a positive integer.


Greatest common divisor
6
Least common multiple36
|a × b|216
Coprime?No




Steps

  1. 18 = 1 × 12 + 6.
  2. 12 = 2 × 6 + 0.
  3. The last non-zero remainder is 6, so gcd = 6.
  4. lcm = |12 × 18| / gcd = 216 / 6 = 36.

Rate This Tool

Your feedback helps us improve SolverCalc.

No public ratings yet






Select a star to save your rating on this device.

Embed GCD and LCM Calculator

Copy this iframe code into a page that permits embeds.


All calculations run locally in your browser. Your entered values are not sent to an external service.

How to Use the GCD and LCM Calculator

Enter two whole numbers and select Calculate GCD and LCM. The tool runs the Euclidean algorithm, reports the positive greatest common divisor, then uses that value to find the least common multiple.

  1. Enter the first and second integers. Negatives are allowed.
  2. Select Calculate GCD and LCM to see the divisor, the multiple, and the division steps.
  3. If the gcd is 1, the numbers are coprime: they share no prime factor.

gcd(0, 0) is left undefined. A zero with a non-zero partner has gcd equal to the non-zero number and lcm 0.

The Euclidean Algorithm

a = q · b + r, then gcd(a, b) = gcd(b, r)

Divide the larger number by the smaller and keep the remainder. Replace the pair with (smaller, remainder) and repeat. When the remainder becomes 0, the other number in the pair is the gcd. This works because any common divisor of a and b also divides the remainder.

Once you have the gcd, the identity |a · b| = gcd(a, b) · lcm(a, b) gives the least common multiple without listing multiples. The lcm is the smallest positive integer that both originals divide, except when a 0 is present, in which case the lcm is 0.

GCD and LCM Examples

12 and 18

18 = 1 × 12 + 6, then 12 = 2 × 6 + 0. The last non-zero remainder is 6, so gcd(12, 18) = 6. Then lcm = 216 / 6 = 36. Both 12 and 18 divide 36, and no smaller positive common multiple exists.

Coprime pair 7 and 13

13 = 1 × 7 + 6, 7 = 1 × 6 + 1, 6 = 6 × 1 + 0. The gcd is 1, so 7 and 13 are coprime. Their lcm is the product 91.

A zero

gcd(0, 5) = 5, because 5 is the largest integer that divides both 0 and 5. Every integer divides 0, so the constraint is 5. The lcm is 0: the only common multiple of 0 and 5 in the non-negative integers that 0 can provide is 0 itself.

48 and 180

180 = 3 × 48 + 36, 48 = 1 × 36 + 12, 36 = 3 × 12 + 0, so gcd = 12 and lcm = 720. This is the pair you meet when simplifying 48/180 to 4/15.

Negatives

gcd(−12, 18) uses the absolute values and still equals 6. Sign does not change which positive integer is the greatest common divisor.

Why GCD and LCM Belong Together

The same prime factors that the Euclidean algorithm captures as a gcd are the ones you cancel when you simplify a fraction, and the ones you keep when you write a least common denominator. The Fraction Calculator on SolverCalc uses that idea when it reduces 1/2 + 1/3 to 5/6: the denominator 6 is lcm(2, 3).

This page does not factor into primes or convert number bases. Those are nearby number-theory topics, but the Euclidean algorithm never needs a factor list.

Common GCD and LCM Mistakes

Listing multiples instead of using the identity

For large numbers, listing 12, 24, 36… is slow. Compute the gcd first, then divide the absolute product by that gcd.

Thinking gcd(0, n) is 0

Every integer divides 0. The greatest common divisor of 0 and n is |n| when n is not 0.

Treating gcd(0, 0) as 0 without comment

There is no largest integer that divides both zeros. This tool leaves that pair undefined.

Forgetting that the gcd is positive

Even when both inputs are negative, report a positive gcd. Common divisors come in ± pairs; the greatest is the positive one.

Using the gcd as a common denominator

Fractions need the lcm of the denominators, not the gcd. The gcd is what you cancel after writing an equivalent fraction.

GCD and LCM FAQs

What is the Euclidean algorithm?

It finds the gcd by replacing the larger number with the remainder after division, repeating until the remainder is 0.

How do you find the LCM from the GCD?

Use lcm(a, b) = |a · b| / gcd(a, b). That identity is why the two results are computed together.

What does coprime mean?

Two integers are coprime when their gcd is 1. They share no prime factor, so their lcm equals the absolute value of their product.

What is gcd(0, 5)?

It is 5. The lcm of 0 and 5 is 0.

Can I enter negative numbers?

Yes. The calculator uses absolute values and reports a positive gcd and a non-negative lcm.

Are my numbers sent to a server?

No. The calculation runs locally in your browser.

Related Calculators

Explore More Number Theory Tools

Continue with divisors, primes, and number-system tools in the SolverCalc collection.

Browse Number Theory & Systems

Reviewed by Prof. Dr. Khalil Mudassar (PhD) · Last updated: [mc_modified_date]

Sources

View references

Disclaimer

This calculator is for general educational use. Review important results before relying on them in professional or cryptographic work. It does not factor integers into primes.