Works on this device
GCD & LCM Calculator
Find the greatest common divisor (GCD, also called GCF or HCF) and the least common multiple (LCM) of a list of numbers. The page shows the working, and it also handles fractions, terms with letters and polynomials.
Enter your values
Check these values
Your values are worked out in this browser. They are not sent to a server.
Your result will show here
Fill in the values, then choose the button below them.
Your result
How it was worked out
How to use this calculator
- Choose what you want to find, for example GCD and LCM of whole numbers.
- Type your numbers, fractions or terms. Separate them with commas or new lines.
- For whole numbers, choose how the working is shown: the Euclidean algorithm, prime factorisation or the division ladder.
- Choose Calculate. You can copy the result, print it, or download it as a CSV file.
The methods
- Euclidean algorithm: divide the larger number by the smaller one. Then divide the old divisor by the remainder. Go on until the remainder is 0. The last divisor is the GCD.
- Prime factorisation: write each number as a product of primes. The GCD uses each prime with its lowest power. The LCM uses each prime with its highest power.
- Division ladder (continuous division): divide all the numbers by a prime that divides every one of them. The product of these primes is the GCD. Then divide by primes that divide at least one number until every number is 1. The product of all the divisors is the LCM.
- LCM from the GCD: LCM(a, b) = a × b ÷ GCD(a, b).
- Least common denominator: the LCM of the bottom numbers of the fractions.
- Terms with letters: the GCF takes the GCD of the numbers in front and the lowest power of each letter. The LCM takes the LCM of the numbers and the highest power of each letter.
- Extended Euclidean algorithm: finds whole numbers x and y with a × x + b × y = GCD(a, b). When the GCD is 1, x gives the inverse of a modulo b.
Worked examples
For 12, 18 and 30: 12 = 2^2 × 3, 18 = 2 × 3^2 and 30 = 2 × 3 × 5. The GCD is 2 × 3 = 6. The LCM is 2^2 × 3^2 × 5 = 180.
For 1071 and 462 with the Euclidean algorithm: 1071 = 2 × 462 + 147, then 462 = 3 × 147 + 21, then 147 = 7 × 21 + 0. The GCD is 21 and the LCM is 1071 × 462 ÷ 21 = 23,562.
For the fractions 3/4, 5/6 and 7/8, the least common denominator is 24. The fractions become 18/24, 20/24 and 21/24.
For the terms 12x^3y^2, 18x^2y^5 and 30x^4y, the GCF is 6x^2y and the LCM is 180x^4y^5. Taking the GCF out of 12x^3 + 18x^2 - 30x gives 6x(2x^2 + 3x - 5).
For the polynomials x^2 - 1 and x^2 + 2x + 1, the GCD is x + 1 and the LCM is x^3 + x^2 - x - 1.
Limits you should know
- Use 2 to 20 whole numbers, each with at most 30 digits. Answers are exact, with no rounding.
- Prime factorisation, the division ladder and the list of common factors work for numbers up to 1,000,000,000,000. The Euclidean algorithm works for every size this page accepts.
- Do not type commas inside a number. Commas separate the numbers in a list.
- For terms and polynomials, the numbers in front must be whole numbers, powers must be whole numbers from 0 to 60, and the letter e cannot be used.
- The polynomial option works with one letter and powers up to 20. Its division steps may show fractions.
- Factoring out the GCF does not factor the part left in brackets. For that, use an algebra tool.