gcd(a, b) · lcm(a, b) = a × b ÷ gcd(a, b)

GCD and LCM calculator

Enter two or more whole numbers to get the greatest common divisor, the least common multiple and whether they are coprime.

Whole numbers separated by commas or spaces — two or more.

Short answer: for 12 and 18 the GCD is 6 and the LCM is 36. For any pair,GCD × LCM = a × b, which is the quickest way to check an answer by hand.

How the Euclidean algorithm works

18 ÷ 12 leaves 6; 12 ÷ 6 leaves 0. The last non-zero remainder, 6, is the GCD. LCM then comes from (12 × 18) ÷ 6 = 36. The same steps repeat across a list, one number at a time, which is why this handles more than two inputs.

Worked example

Bus A arrives every 12 minutes and bus B every 18. They coincide every LCM(12, 18) = 36 minutes. Cutting a 48 cm × 36 cm sheet into the largest equal squares: GCD(48, 36) = 12 cm squares.

GCD and LCM questions

What is the difference between GCD and LCM?

The greatest common divisor is the largest number that divides all of them; the least common multiple is the smallest number all of them divide. For 12 and 18, GCD is 6 and LCM is 36, and GCD × LCM = 12 × 18 for any pair.

How is the GCD computed?

By the Euclidean algorithm: divide the larger number by the smaller and replace the pair with the smaller number and the remainder, repeating until the remainder is zero. It is fast and exact, which is why it is used here instead of trial division.

Where would I use the LCM?

Adding fractions with different denominators, finding when two repeating events coincide (buses every 12 and 18 minutes meet every 36), and gear or wheel ratio problems.

What does coprime mean?

Two numbers are coprime when their only common divisor is 1, so the GCD is 1 — 9 and 28, for example. That matters for fractions, modular arithmetic and RSA-style key maths.

Related tools