➗ GCD & LCM Calculator
Enter two or more integers and instantly get the greatest common divisor (GCD) and least common multiple (LCM). Handy for simplifying fractions, homework, or lining up events that repeat on different cycles.
How to use
- Enter two or more integers (use "Add number" to add up to 6).
- The GCD and LCM are calculated automatically.
How the calculation works
The greatest common divisor (GCD) is the largest integer that divides all of the given numbers. This tool finds it with the Euclidean algorithm, which relies on the fact that if dividing a by b leaves remainder r, then GCD(a, b) = GCD(b, r). You keep dividing until the remainder is zero; the last divisor is the GCD. It is far faster than going through prime factorisation, reaching the answer in a handful of divisions even for large numbers. The least common multiple (LCM) is the smallest positive integer divisible by all of them. For two numbers, a × b = GCD(a, b) × LCM(a, b), so LCM = a ÷ GCD × b. Dividing before multiplying keeps intermediate values from growing unnecessarily large. With three or more numbers, the calculation is simply repeated pairwise.
Worked example
Finding GCD(1071, 462) with the Euclidean algorithm 1. 1071 ÷ 462 = 2 remainder 147 2. 462 ÷ 147 = 3 remainder 21 3. 147 ÷ 21 = 7 remainder 0 The divisor at the step where the remainder hits zero, 21, is the GCD. For 12, 18 and 30: GCD(12, 18) = 6 and GCD(6, 30) = 6, so the GCD is 6. For the LCM, LCM(12, 18) = 36 and LCM(36, 30) = 180. Events repeating every 12, 18 and 30 days all coincide every 180 days.
Things to be aware of
- Positive integers only; zero, negatives and decimals are excluded.
- The LCM grows quickly with more and larger inputs. Beyond the range JavaScript numbers represent exactly (about 9 quadrillion), results lose precision.
- To reduce a fraction, divide numerator and denominator by their GCD.
- Two numbers whose GCD is 1 are called coprime.
FAQ
Can I calculate the GCD/LCM of more than 2 numbers?
Yes — use the "Add number" button to add up to 6 numbers, and the tool computes the GCD and LCM across all of them.
Is this useful for simplifying fractions?
Yes — dividing both the numerator and denominator by their GCD simplifies a fraction to its lowest terms.
Can I enter decimals or negative numbers?
This tool only supports positive integers. Decimals and negative values are excluded from the calculation.