GCD and LCM calculator

Enter two or more whole numbers to get their greatest common divisor, least common multiple and prime factors.

GCD

How it works

The GCD uses Euclid’s algorithm, gcd(a, b) = gcd(b, a mod b), applied to each number in turn. The LCM uses lcm(a, b) = a × b ÷ gcd(a, b). Prime factors come from trial division.

Worked example

  1. 12 = 2² × 3, 18 = 2 × 3², 30 = 2 × 3 × 5
  2. GCD = 2 × 3 = 6
  3. LCM = 2² × 3² × 5 = 180

Frequently asked questions

What is the GCD?

The greatest common divisor (also GCF or HCF) is the largest number that divides all the given numbers without a remainder. It is used to simplify fractions.

What is the LCM?

The least common multiple is the smallest number that all the given numbers divide into. It is the common denominator used to add fractions.

How are GCD and LCM related?

For two numbers, GCD × LCM = a × b. For 12 and 18: 6 × 36 = 216 = 12 × 18.