GCD / LCM Calculator

Greatest common divisor and least common multiple of any list of integers.

Open tool

Overview

The GCD / LCM Calculator finds the greatest common divisor and least common multiple of any list of integers. Type in two, three or twenty numbers and out come the largest integer that divides all of them and the smallest integer they all divide into.

It is built for fraction problems, scheduling questions ("when do two timers coincide?"), cryptography demos and gear-ratio puzzles. Both values come up constantly in elementary number theory and in any algorithm that reduces fractions to lowest terms.

How it works

GCD is computed via the Euclidean algorithm: gcd(a, b) = gcd(b, a mod b) with gcd(a, 0) = a. It extends to a list by reducing left to right: gcd(a, b, c) = gcd(gcd(a, b), c). The number of iterations grows only logarithmically with the smaller input — even huge numbers reduce in milliseconds.

LCM uses the identity lcm(a, b) = |a * b| / gcd(a, b). To avoid intermediate overflow, the implementation divides first: lcm(a, b) = (a / gcd(a, b)) * b. Extending to lists works the same way, folding through the values.

Examples

gcd(12, 18)  →  6
lcm(4, 6)  →  12
gcd(48, 18, 30)  →  6
lcm(2, 3, 5, 7)  →  210

FAQ

What if one input is zero?

By convention gcd(a, 0) = a and gcd(0, 0) = 0. The LCM of any list containing zero is zero.

Does it handle negative numbers?

Yes — both GCD and LCM are taken as non-negative regardless of sign. gcd(-12, 18) = 6.

How big can the numbers be?

The calculator uses big integers, so arbitrarily large inputs work. The Euclidean algorithm is fast even for thousand-digit operands.

Why is gcd(a, b) * lcm(a, b) = a * b?

It's a fundamental identity for two integers. Multiplying together every prime factor at its higher exponent times every prime factor at its lower exponent recovers the full product a * b.

Can I use it for fractions?

To reduce a / b to lowest terms, divide both by gcd(a, b). To add fractions, use the LCM of the denominators as the common denominator.

Try GCD / LCM Calculator

An unhandled error has occurred. Reload ×