GCD & LCM Calculator

Find the greatest common divisor and least common multiple of any list of integers.

How this works

The greatest common divisor (GCD) is the largest integer that divides every number in your list with no remainder. The least common multiple (LCM) is the smallest positive integer that every number in the list divides into. Used in fraction simplification (divide top and bottom by the GCD) and finding common denominators (LCM of the denominators). Paste any list of whole numbers and the calculator returns both at once.

The formula

GCD via Euclidean algorithm: while b ≠ 0: (a, b) := (b, a mod b) return a LCM(a, b) = |a × b| / GCD(a, b) For more than two numbers, reduce pairwise.

a, b: positive integers (signs are stripped — Euclid works on |a|, |b|). The algorithm dates to Euclid's Elements c. 300 BC and is one of the oldest non-trivial algorithms still in everyday use. The pairwise reduction property — gcd(a, b, c) = gcd(gcd(a, b), c) — lets us extend it to any number of inputs without rewriting the loop.

Example calculation

  • Numbers: 12, 18, 24
  • GCD: gcd(12, 18) = 6, then gcd(6, 24) = 6 → GCD = 6
  • LCM: lcm(12, 18) = 36, then lcm(36, 24) = 72 → LCM = 72
  • 12 × 18 × 24 = 5184. GCD × LCM = 6 × 72 = 432. The relationship a × b = gcd(a,b) × lcm(a,b) only generalises cleanly to two numbers.

Frequently asked questions

How do I use this to simplify a fraction?

Find the GCD of the numerator and denominator, then divide both by it. For 18/24: GCD(18, 24) = 6, so 18/24 = (18÷6)/(24÷6) = 3/4. The fraction is fully simplified when GCD = 1 — at that point you can't reduce any further.

When would I need the LCM?

Most often when adding or comparing fractions with different denominators — the LCM of the denominators gives the smallest common denominator. Also useful for scheduling problems ("when do these two events line up again?"), gear ratios, and synchronising periodic processes.

Does GCD work with negative numbers or zero?

The calculator strips signs before running Euclid, so −12 and 12 are treated identically. GCD(0, n) is defined as |n|, since every integer divides 0. LCM involving 0 is conventionally 0 (because the only multiple of every integer including 0 is 0 itself).

Related calculators