Skip to content
K Knidox Search…
Math · Number Theory

GCD & LCM

Find the GCD and LCM of any list of integers, with prime factorizations.

Positive integers, separated by commas or spaces (e.g. 12, 18).
GCD (greatest common divisor)
6
LCM (least common multiple)
36

12, 18 — 2 numbers.

The GCD (greatest common divisor) is the largest number that divides every input evenly; the LCM (least common multiple) is the smallest number every input divides into. Since 12 = 2²·3 and 18 = 2·3², GCD(12, 18) = 2·3 = 6 and LCM(12, 18) = 2²·3² = 36.

GCD and LCM from prime factors

Every integer breaks into a unique product of primes. Once you have those factorizations, the GCD is the product of the primes the numbers share, each taken to its lowest power; the LCM is the product of all primes that appear, each taken to its highest power. For 12 = 2²·3 and 18 = 2·3², the shared lowest powers give 2¹·3¹ = 6, and the combined highest powers give 2²·3² = 36.

LCM(a, b) = a × b ÷ GCD(a, b)

for two positive integers; extend to a list by folding the operation pairwise

Worked example

Find the GCD and LCM of 12 and 18:

  1. 1
    Factor each number into primes. 12 = 2² · 3 and 18 = 2 · 3².
  2. 2
    GCD: multiply the shared primes at their lowest powers. Both share 2¹ and 3¹, so GCD = 2 · 3 = 6.
  3. 3
    LCM: multiply every prime at its highest power. Take 2² and 3², so LCM = 4 · 9 = 36.
  4. 4
    Check with the product rule. GCD × LCM = 6 × 36 = 216 = 12 × 18, confirming the answer.

GCD and LCM of common pairs

The GCD divides both numbers; the LCM is the smallest multiple of both.

PairPrime factorsGCDLCM
12, 182²·3 and 2·3²636
8, 122³ and 2²·3424
7, 137 and 13191
15, 253·5 and 5²575
6, 10, 152·3, 2·5, 3·5130
4, 6, 82², 2·3, 2³224

Euclid’s algorithm, coprime numbers, and the product rule

Euclid’s algorithm. You don’t need to factor large numbers to find the GCD. Repeatedly replace the larger number with the remainder of dividing it by the smaller, until the remainder is 0 — the last nonzero value is the GCD. This is fast even for huge inputs.

Coprime numbers. When GCD = 1 the numbers share no common prime factor and are called coprime (or relatively prime). For coprime a and b, the LCM is simply a × b — for example 7 and 13 are coprime, so LCM(7, 13) = 91.

The product rule. For any two positive integers, GCD(a, b) × LCM(a, b) = a × b. That identity is exactly why LCM(a, b) = a × b ÷ GCD(a, b).

What is the difference between the GCD and the LCM?
The GCD (greatest common divisor) is the largest number that divides all the inputs without a remainder, while the LCM (least common multiple) is the smallest number that all the inputs divide into. For 12 and 18, the GCD is 6 and the LCM is 36.
What does it mean for numbers to be coprime?
Two numbers are coprime (relatively prime) when their GCD is 1 — they share no common prime factor. For coprime numbers the LCM equals their product, so LCM(7, 13) = 7 × 13 = 91.
How does Euclid’s algorithm find the GCD?
Replace the larger number with the remainder of dividing it by the smaller, and repeat until the remainder is 0. The last nonzero remainder is the GCD. It avoids factoring entirely and is fast even for very large numbers.
How are the GCD and LCM related?
For two positive integers, GCD × LCM = a × b. So once you know the GCD you can get the LCM as a × b ÷ GCD — for 12 and 18 that is 12 × 18 ÷ 6 = 36.
Can I enter more than two numbers?
Yes. Enter any list of positive integers separated by commas or spaces. The GCD and LCM are computed by folding the two-number operation across the whole list, and each number’s prime factorization is shown.
How are the prime factorizations used?
The GCD is the product of the shared primes at their lowest powers, and the LCM is the product of every prime that appears at its highest power. Since 12 = 2²·3 and 18 = 2·3², GCD = 2·3 = 6 and LCM = 2²·3² = 36.