GCD & LCM Calculator
Enter two or more whole numbers to see their greatest common divisor and least common multiple, with the working shown.
GCD (greatest common divisor)
6
LCM (least common multiple)
180
Every number in the list is divisible by 6.
Euclidean algorithm for the first pair
Each line divides the larger number by the smaller and keeps the remainder. The last non-zero remainder is the GCD of the pair.
18 = 1 × 12 + 6 12 = 2 × 6 + 0
With more than two numbers the result folds across the list: gcd(a, b, c) = gcd(gcd(a, b), c). The LCM folds the same way, using lcm(a, b) = a × b ÷ gcd(a, b) at each step.
Prime factorizations
- 12 = 2^2 × 3
- 18 = 2 × 3^2
- 30 = 2 × 3 × 5
Trial division stops at 100,000, so very large numbers may show an unfactored remainder. The GCD and LCM above are exact regardless.
All calculations run locally in your browser — nothing you enter is uploaded.
How it works
- Type 2 to 20 positive whole numbers, separated by commas or spaces.
- Read the GCD and LCM, which update live as you edit the list.
- Expand the steps to follow the Euclidean algorithm for the first pair, or open the prime factorization view to see each number broken into primes.
Frequently asked questions
- How does the calculator find the GCD of more than two numbers?
- It uses the Euclidean algorithm, which repeatedly replaces the larger number with the remainder of dividing it by the smaller one until the remainder is zero. For a longer list it folds pairwise: gcd(a, b, c) equals gcd(gcd(a, b), c), so the same two-number routine is applied across the whole list. The steps panel shows this division chain for the first pair.
- How is the LCM computed, and can it overflow?
- The LCM of a pair is a × b ÷ gcd(a, b), folded across the list the same way as the GCD. All arithmetic uses BigInt, JavaScript’s arbitrary-precision integer type, so results are exact no matter how large the LCM grows — there is no 53-bit floating-point limit and no rounding.
- Are my numbers sent to a server?
- No. Every calculation, including the prime factorizations, runs locally in your browser with JavaScript. Nothing is transmitted, logged, or stored anywhere, and the page keeps working if you go offline after it loads.
- What does it mean when the numbers are coprime?
- Numbers are coprime (or relatively prime) when their GCD is 1, meaning they share no prime factor. The calculator flags this case explicitly. Note that a set can be coprime as a whole without every pair being coprime — 6, 10, and 15 have GCD 1, yet each pair shares a factor.
- What are GCD and LCM actually used for?
- The GCD reduces fractions to lowest terms, simplifies ratios, and sizes the largest equal groups a set can be split into. The LCM finds the first moment repeating cycles align — bus schedules, gear rotations, blinking lights — and gives the common denominator when adding fractions. Both appear constantly in modular arithmetic and number theory homework.
About this tool
This calculator takes a list of 2 to 20 positive whole numbers and returns their greatest common divisor (GCD, also called HCF) and least common multiple (LCM) instantly, updating as you type. Alongside the two results it shows the actual Euclidean algorithm division steps for the first pair of numbers, explains how the computation folds across a longer list, and offers a prime-factorization view of every number you entered. When the GCD is 1 it tells you the numbers are coprime.
Under the hood everything is exact integer arithmetic on BigInt values, so numbers far beyond the usual 15–16 digit floating-point ceiling are handled without error — you can enter values up to 30 digits long. The GCD comes from the classic Euclidean algorithm: divide, keep the remainder, repeat until the remainder is zero; the last non-zero remainder is the answer. The LCM is then derived as a × b ÷ gcd(a, b), which avoids ever multiplying before reducing. All of this runs client-side in your browser; nothing you type leaves your device.
The step-by-step view makes the tool useful for learning, not just checking answers. Each line shows the division identity a = q × b + r, exactly the format math teachers expect in written work. The factorization panel expresses each number as a product of prime powers, which is the textbook alternative route to both GCD (take the lowest shared exponents) and LCM (take the highest), so you can verify the result two independent ways.
Practical tip: to reduce a fraction, enter its numerator and denominator and divide both by the GCD shown. To find when two repeating events next coincide, enter their cycle lengths and read the LCM. For very large inputs the factorization view may report a large unfactored remainder — trial division stops at 100,000 — but the GCD and LCM themselves are always exact.