GCD & LCM Calculator
GCD and LCM of two or more integers by the Euclidean algorithm, with the division steps, the prime factorisations and the simplified ratio — exact, any size.
GCD and LCM (exact, any size), the Euclid steps for the first pair, each number’s prime factorisation, the ratio divided through by the GCD, and whether the numbers are coprime.
Example: 48 and 18: 48 = 18 × 2 + 12, 18 = 12 × 1 + 6, 12 = 6 × 2 + 0, so GCD 6 and LCM 144; 12, 18, 30 have GCD 6, LCM 180 and simplify to 2 : 3 : 5.
Euclid,
two thousand years on.
How the GCD is found, why the LCM follows from it, and what the factorisations add.
The algorithm
gcd(a, b) = gcd(b, a mod b) until the remainder is zero; the last non-zero remainder is the GCD. For 48 and 18: 48 = 18 × 2 + 12, 18 = 12 × 1 + 6, 12 = 6 × 2 + 0, so the GCD is 6. The steps for the first pair are printed; for more numbers the GCD is folded through the list. Integers of any size are handled exactly.
LCM and ratio
lcm(a, b) = |a·b| ÷ gcd(a, b), applied pairwise across the list without ever forming the full product. Dividing every number by the GCD gives the simplest whole-number ratio (12 : 18 : 30 → 2 : 3 : 5). With a zero the LCM is undefined and is shown as a dash; signs are ignored.
Factorisations
Each number is factorised by trial division up to 10⁷ — enough for anything you would type by hand; a larger prime factor left at the end is shown as found and marked. The GCD is the product of the shared primes at their lowest powers and the LCM at their highest, which the factorisations let you see. Nothing leaves the browser; the same four anonymous usage counts as the rest of the site apply.
SOURCES
- Euclidean algorithm gcd(a, b) = gcd(b, a mod b); lcm(a, b) = |ab| ÷ gcd(a, b) folded over the list; factorisation by trial division to 10⁷
Last reviewed 21 September 2026. How results are checked: How we verify.