GCD and LCM calculator

Greatest common divisor and least common multiple for several numbers, with prime factors and divisors.

The three belong together: once you have the prime factorisation, the GCD and LCM read straight off it. Take the common primes at their lowest powers for the GCD, and every prime at its highest power for the LCM. Two numbers or many — both work.

Numbers

Two or many. Positive whole numbers only.

Divisors and multiples

Greatest common divisor

6

Least common multiple

5,040

Each number

NumberPrime factorsDivisorsPrime
482^4 × 310no
1802^2 × 3^2 × 518no
2102 × 3 × 5 × 716no

Common primes at their lowest powers give the GCD; every prime at its highest power gives the LCM.

Values beyond the safe integer range (about 9.007 quadrillion) may lose accuracy.

Working 48, 180 and 210 by hand

The three defaults factorise as 48 = 2⁴×3, 180 = 2²×3²×5 and 210 = 2×3×5×7. The primes present in all three are 2 and 3; at their lowest powers that is 2×3 = 6, the GCD. The LCM gathers every prime that appears, each at its highest power: 2⁴×3²×5×7 = 5,040. The divisor count in the table adds one to each exponent and multiplies, so 48 has (4+1)(1+1) = 10 divisors, 180 has 3×3×2 = 18 and 210 has 2⁴ = 16.

The GCD is found without factorising

The screen uses Euclid's algorithm: replace the larger number by the remainder of dividing it by the smaller, and repeat until the remainder is zero. For 180 and 48, 180 = 3×48 + 36, 48 = 1×36 + 12, 36 = 3×12 + 0, so the answer is 12. With more than two numbers the result is fed back in with the next one — gcd(12, 210) = 6. The LCM goes pairwise the same way: lcm(48, 180) = 48×180÷12 = 720, then lcm(720, 210) = 720÷30×210 = 5,040. Dividing before multiplying keeps the intermediate value from overflowing as early.

Prime factors are searched only up to the square root

At most one prime factor of n can be larger than √n. So 2 and 3 are stripped first, then only candidates of the form 6k±1 (5, 7, 11, 13, …) are tried up to √n, and whatever is left above 1 is the last prime factor. A ten-digit prime such as 1,000,000,007 is settled in a little over 30,000 trial divisions. A number marked prime in the table has itself as its only prime factor and exactly two divisors, 1 and itself. 1 is not prime and has an empty factorisation.

How the input is read

Commas, semicolons, spaces and line breaks all separate numbers. Decimals are truncated to integers (3.7 becomes 3), and zero and negatives are dropped. With a single number the GCD and LCM are that number itself. With two or more numbers and a GCD of 1, the screen says they are coprime. The LCM grows quickly, and beyond about 9.007 quadrillion (2⁵³) its last digits cannot be trusted — the product of two coprime eight-digit numbers is already in that neighbourhood.

Common questions

QWhy is the LCM not just the product?

Only when the numbers are coprime. Shared factors would be counted twice, so the product is divided by the GCD — lcm(a,b) = a × b ÷ gcd(a,b). For 4 and 6 that is 12, not 24.

QIs 1 a prime?

No. A prime is a natural number greater than 1 whose only divisors are 1 and itself. Admitting 1 would break unique factorisation, since any number of 1s could be multiplied in.

Source last checked: 2026-08-22

This tool does not replace tax or investment advice; the result is for reference.