LCM Calculator

Find the least common multiple (LCM) of any list of integers — built on the Euclidean GCD algorithm.

How this works

The least common multiple (LCM) of a set of integers is the smallest positive integer that every number in the set divides into without a remainder. The most common everyday use is adding fractions: to compute 1/4 + 1/6 you find the LCM of 4 and 6 (which is 12), then convert each fraction to twelfths and add. The calculator computes LCM via the GCD identity — lcm(a, b) = a × b / gcd(a, b) — using the Euclidean algorithm for the GCD. For three or more numbers it reduces pairwise: lcm(a, b, c) = lcm(lcm(a, b), c).

The formula

lcm(a, b) = |a × b| / gcd(a, b) For a list: lcm(a, b, c, …) = lcm(lcm(a, b), c, …) gcd via Euclidean algorithm: while b ≠ 0: (a, b) := (b, a mod b) return a

a, b: positive integers (signs are stripped — the formula uses |a|, |b|). The lcm-via-gcd identity is exact for any pair of integers and avoids the naive "list multiples until you find a match" approach, which would be O(min(a, b)) — slow for large numbers. Pairwise reduction extends to any number of inputs in O(n) calls to the underlying GCD.

Example calculation

  • Numbers: 4, 6, 8
  • lcm(4, 6) = |4 × 6| / gcd(4, 6) = 24 / 2 = 12
  • lcm(12, 8) = |12 × 8| / gcd(12, 8) = 96 / 4 = 24
  • LCM(4, 6, 8) = 24. Check: 24 / 4 = 6, 24 / 6 = 4, 24 / 8 = 3 — all whole numbers, so 24 is divisible by all three. ✓

Frequently asked questions

Why use the GCD identity instead of listing multiples?

Listing multiples works for small numbers (lcm of 4 and 6: 4, 8, 12 — match!), but it scales poorly. lcm(99, 100) needs you to list nearly 100 multiples before finding the answer; lcm(99,991, 100,000) would need millions. The GCD identity reduces every problem to one Euclidean-algorithm call, which converges in roughly log₂(min(a, b)) steps regardless of size. So lcm(99,991, 100,000) takes maybe 16 steps instead of 99,991. Same answer, vastly faster.

When would I actually need the LCM in real life?

Most often: adding or subtracting fractions with different denominators. To compute 3/4 + 5/6 you need a common denominator — the LCM of 4 and 6 (which is 12). Other places it shows up: scheduling repeating events that need to coincide ("Bus A comes every 8 minutes, Bus B every 12 minutes — when do they next arrive together?" → LCM = 24 minutes), gear ratios, music theory (when do two rhythms align?), and competitive maths puzzles. If you're past school age and never thought about it again, fraction addition is probably the only place you'll meet it.

What if I include 0 or a negative number?

Negatives are stripped — the algorithm operates on absolute values, so lcm(−4, 6) = lcm(4, 6) = 12. That's the standard mathematical convention; some texts define LCM only on positive integers, but stripping signs is the harmless and useful generalisation. Including 0 makes lcm(0, anything) = 0, which is mathematically correct but rarely useful — if you see a 0 result, double-check your input.

Is there a closed-form for LCM of more than two numbers?

Not in the way GCD has. For three numbers you can write lcm(a, b, c) = a × b × c / gcd(gcd(a, b) × gcd(b, c) × gcd(a, c), …) but it gets ugly fast and isn't faster than just doing pairwise reduction: lcm(a, b, c) = lcm(lcm(a, b), c). The pairwise version is what every standard library and textbook uses, including this calculator. The relationship a × b × c × … = gcd(…) × lcm(…) only generalises cleanly to two numbers; for more than two, GCD × LCM ≠ product.

Related calculators