How to use it
- Type two or more whole numbers in Whole numbers, separated by commas, spaces or line breaks.
- Read GCD (greatest common divisor) and LCM (least common multiple). The result updates as you type.
- Check Prime factors of each number to see what each number is made of.
- Go through How it is worked out to follow Euclid's algorithm line by line.
How the GCD and LCM are found
The GCD is found with Euclid's algorithm. Divide the larger number by the smaller one and keep the remainder. Then divide the smaller number by that remainder, and repeat. When the remainder is 0, the last divisor is the GCD. The method works for any two whole numbers.
For more than two numbers, the GCD is taken pair by pair: the GCD of the first two, then the GCD of that result and the third number, and so on. The answer does not depend on the order.
GCD(a, b) by Euclid: a = q × b + r, then b = q₂ × r + r₂, until the remainder is 0
LCM(a, b) = a × b ÷ GCD(a, b)
Prime factors as a check
Each number is split into prime factors by trial division with 2, 3, 5 and then the numbers that are not multiples of 2, 3 or 5. Numbers left above 10,000 are tested for primality and split with Pollard's rho method.
The prime factors give the same answers. The GCD takes each prime that all numbers share, with its lowest power. The LCM takes every prime that appears, with its highest power. For 84 and 126 the shared primes are 2, 3 and 7, so the GCD is 2 × 3 × 7 = 42.
What the calculator accepts
- Whole numbers of any length, such as 84 or 123456789012345678901234567890.
- Up to 20 numbers in one list, separated by commas, spaces or line breaks.
- Not supported: decimals such as 1.5, negative numbers and thousands marks. The prime factors are worked out for numbers up to 10¹⁸.
Worked example: 84 and 126
84 = 2² × 3 × 7 and 126 = 2 × 3² × 7. Euclid's algorithm gives 126 = 1 × 84 + 42 and then 84 = 2 × 42 + 0, so the GCD is 42.
The LCM is 84 × 126 ÷ 42 = 252. As a check, GCD × LCM = 42 × 252 = 10,584, which is the same as 84 × 126.
| Result | |
|---|---|
| GCD | 42 |
| LCM | 252 |
| GCD × LCM, which equals 84 × 126 | 10,584 |
Frequently asked questions
What is the difference between the GCD and the LCM?
The GCD is the largest whole number that divides every number in the list. The LCM is the smallest positive whole number that every number divides into. For 4 and 6 the GCD is 2 and the LCM is 12.
How does Euclid's algorithm work?
Divide the larger number by the smaller one and keep the remainder. Divide the smaller number by that remainder, and keep going until the remainder is 0. The last divisor is the GCD, and each line of the working is shown in the steps.
Can I enter more than two numbers?
Yes, up to 20 numbers in one list. The GCD and the LCM are taken pair by pair from left to right, and the final answer is the same whatever the order of the numbers.
Why is the LCM 0 when one of the numbers is 0?
Zero is a multiple of every number. By the usual convention, a list that contains 0 has the LCM 0, and the GCD ignores the 0 unless every number is 0.
Does it work with very large numbers?
Yes. The GCD and the LCM are exact for numbers of any length. The prime factors are worked out for numbers up to 10¹⁸; above that, the table shows a dash.
Are the numbers I type sent to a server?
No. The calculation runs in your browser, and nothing you type is sent to us.
Sources
- Wikipedia: Euclidean algorithm
- Wikipedia: Greatest common divisor
- Wikipedia: Least common multiple
- Wikipedia: Integer factorization, with trial division and Pollard's rho
Figures and text last checked on Tuesday, November 10, 2026.