Find the GCD and LCM of two or more whole numbers of any size, with the Euclidean algorithm, prime factorisations, Bezout coefficients and common divisors shown.
Initializing in your browser…
Check whether any whole number is prime, and see its prime factors, divisors, nearby primes and Goldbach pairs, or list every prime in a range.
A scientific calculator with exact fractions and decimals, degrees or radians, 34 functions and a desk-calculator mode. Rounded answers are labelled as rounded.
Plot up to eight functions of x, find their roots, turning points and intersections, shade integrals and draw derivatives. Pan, zoom and share any graph.
Two buses leave the same stop, one every 12 minutes and one every 18 minutes. You want to know how often they leave together, with the working.
Numbers
12 18
Result
GCD: 6 LCM: 36 18 = 1 x 12 + 6 12 = 2 x 6 + 0 12 = 2^2 x 3, 18 = 2 x 3^2 Check: 6 x 36 = 216 = 18 x 12
The buses leave together every 36 minutes, the lowest common multiple of 12 and 18. The Euclidean algorithm finds the GCD first: 18 divided by 12 leaves 6, and 12 divided by 6 leaves nothing, so the GCD is 6. The LCM then follows as 12 / 6 x 18 = 36. The factorisations give the same answers another way: the shared primes at their lowest powers, 2 x 3, make 6, and every prime at its highest power, 2^2 x 3^2, makes 36. Multiplying the GCD by the LCM gives 216, which is exactly 12 x 18, as it must be for any two numbers.
Find the greatest common divisor (GCD) and the lowest common multiple (LCM) of two or more whole numbers, however many digits they have. The page writes out the Euclidean algorithm, the prime factorisation of every number, the Bezout coefficients and the full list of common divisors, and checks its own answer.
Two answers, any size. Type whole numbers into the boxes, one per box, and add as many boxes as you need. The GCD is the largest number that divides all of them exactly, and the LCM is the smallest positive number that all of them divide into. Both are worked out with exact whole-number arithmetic, so a twenty-digit input is as precise as a two-digit one and every digit of the answer is shown. That matters more than it sounds: the LCM of 123,456,789 and 987,654,321 is 13,548,070,123,626,141, and a calculator that multiplies the two numbers in ordinary floating point before dividing by the GCD comes out one short. You can paste a list such as 12, 18, 24 to fill several boxes at once, and thousands separators such as 1,000,000 are read as part of the number.
The working, written out. For two numbers the Euclidean algorithm is shown line by line in the form a = q x b + r, starting with the larger number and ending at the line where the remainder reaches zero; the divisor in that line is the GCD. For a longer list the page shows how the answer is built two numbers at a time, such as gcd(6, 10) = 2 and then gcd(2, 15) = 1. The prime factorisation of every number gives a second route to the same answers: the GCD takes the lowest power of each prime the numbers share, and the LCM takes the highest power of each prime in any of them. Large numbers with no small factors are factorised in the background, so the page stays responsive, and a Stop button appears while that work is running.
Bezout coefficients and common divisors. For two numbers the page also gives whole numbers x and y with ax + by = gcd(a, b). They come from the extended Euclidean algorithm and are what you need to find a modular inverse or to solve a linear equation in whole numbers. The common divisors are listed in full, and they are exactly the divisors of the GCD.
Checked, and clear about edge cases. For two numbers, GCD x LCM always equals the product of the numbers, and the page works out both sides and shows that they agree. Zero is handled by definition: gcd(0, n) is n, because every number divides zero, and lcm(0, n) is 0. Negative numbers are accepted and give the same positive GCD and LCM as their sizes. When a list of three or more has a GCD of 1, the page also says whether some pair still shares a factor, as 6, 10 and 15 do. A decimal, a number in exponent notation or a box holding two numbers is pointed out, and no answer is shown until it is fixed.
GCD 6 and LCM 36. The algorithm takes two lines: 18 = 1 x 12 + 6, then 12 = 2 x 6 + 0.
GCD 6 and LCM 8,640, reached in four steps: 270 = 1 x 192 + 78, 192 = 2 x 78 + 36, 78 = 2 x 36 + 6 and 36 = 6 x 6 + 0.
GCD 1 and LCM 30. No number above 1 divides all three, yet every pair shares a factor: 6 and 10 share 2.
123,456,789 and 987,654,321 have GCD 9 and LCM 13,548,070,123,626,141, with every digit exact.
Divide the top and bottom by their GCD: the GCD of 84 and 126 is 42, so 84/126 is 2/3.
The LCM of the denominators is the lowest common denominator: for 5/12 + 7/18 it is 36.
Two buses that leave every 12 and every 18 minutes leave together again every 36 minutes, their LCM.
When the GCD is 1, the Bezout coefficients give a modular inverse directly, a step used in number theory and cryptography.
Every line of the Euclidean algorithm is written in the same form you would use on paper.
Divide the larger by the smaller and keep the remainder, then divide the smaller number by that remainder, and repeat until the remainder is 0. The last divisor is the GCD. For 18 and 12: 18 = 1 x 12 + 6, then 12 = 2 x 6 + 0, so the GCD is 6. This is the Euclidean algorithm, and the page writes it out for you.
Divide one number by the GCD and multiply by the other. For 12 and 18 the GCD is 6, so the LCM is 12 / 6 x 18 = 36. Dividing first keeps the numbers small, which is part of why the answer stays exact for very large inputs.
There is no fixed limit. The GCD, the LCM, the Euclidean algorithm and the Bezout coefficients are exact for numbers with hundreds of digits. Factorising a very large number with no small prime factors can take a while; it runs in the background, and if part of a number cannot be broken down in reasonable time the page says so.
The number itself, ignoring its sign, because every number divides 0. The LCM of 0 and any number is 0, since 0 is the only multiple of 0. The GCD of 0 and 0 is taken to be 0.
Two numbers are coprime when their only common divisor is 1, so their GCD is 1 and their LCM is their product, as with 8 and 15. For a longer list, a GCD of 1 does not make every pair coprime: 6, 10 and 15 have a GCD of 1, but 6 and 10 share 2.
For any two whole numbers a and b there are whole numbers x and y with ax + by = gcd(a, b). For 12 and 18, 12 x (-1) + 18 x 1 = 6. The coefficients come from the extended Euclidean algorithm and are used to find modular inverses and to solve equations such as ax + by = c in whole numbers.
Yes. The GCD and the LCM are given as positive numbers, the same as for the sizes of the numbers, and the factorisation of a negative number starts with -1.
Every calculation runs locally in your browser. Your numbers and expressions are not transmitted or stored.