GCD & LCM Calculator

Find the greatest common divisor and least common multiple of any integers — with Euclid steps.

Ad placeholder (leaderboard)
Enjoying the tools? Go Pro for £4.99 (one-time) and remove all ads — forever, on this device. Remove ads — £4.99

This calculator finds the greatest common divisor (GCD) and least common multiple (LCM) of any list of whole numbers, and shows the full working behind both. The GCD — also called the highest common factor (HCF) — is the largest integer that divides every value exactly; the LCM is the smallest positive integer that every value divides into. Together they are the workhorses of arithmetic: you need the GCD to simplify fractions to lowest terms, and the LCM to find the common denominator when adding fractions or to predict when two repeating cycles line up again.

How it works

The tool parses your input, splits it on commas or spaces, keeps only whole non-zero numbers, and then computes both results in a single pass while recording the steps:

  • GCD uses the Euclidean algorithm: repeatedly replace the pair (a, b) with (b, a mod b) until the remainder reaches zero — the last non-zero value is the GCD. For several numbers it folds them pairwise, since GCD(a, b, c) = GCD(GCD(a, b), c). This is dramatically faster than listing factors because each division shrinks the numbers.
  • LCM is derived from the GCD by LCM(a, b) = |a × b| ÷ GCD(a, b), chained across the list. Dividing by the GCD before multiplying keeps the intermediate values as small as possible.
  • A prime-factor table shows each prime’s exponent in every number. The GCD takes the minimum exponent of each shared prime; the LCM takes the maximum exponent of every prime that appears. This is the conceptual picture behind the two algorithms.

Negative inputs use their absolute value, and at least two non-zero numbers are required. Because JavaScript integers are exact only up to 2^53 − 1, the tool flags an LCM that would exceed that range rather than show a rounded value.

Worked example

Enter 12, 18, 24. Factoring gives 12 = 2^2 × 3, 18 = 2 × 3^2, and 24 = 2^3 × 3.

  • GCD — take the lowest power of each shared prime: 2^1 × 3^1 = 6. The Euclidean trace confirms it: GCD(12, 18) runs 18 = 1×12 + 6, 12 = 2×6 + 0, giving 6; then GCD(6, 24) = 6.
  • LCM — take the highest power of every prime: 2^3 × 3^2 = 72. Folding pairwise, LCM(12, 18) = 36, then LCM(36, 24) = 72.

So 6 divides all three numbers, and 72 is the smallest number all three divide into.

Formula note. GCD via the Euclidean algorithm; LCM(a, b) = |a·b| ÷ GCD(a, b); and for any two positive integers the identity GCD(a, b) × LCM(a, b) = a × b holds — the calculator prints this check for two-number inputs.

NumbersGCDLCM
12, 18636
12, 18, 24672
8, 151120
100, 75, 5025300

The first two rows share a GCD of 6 but differ in LCM, while 8 and 15 are coprime (GCD = 1), so their LCM is simply their product. Everything runs in your browser, so nothing you enter is uploaded.

Ad placeholder (rectangle)