GCD & LCM Calculator
GCD (HCF) and LCM of two or more whole numbers, with the prime factors shown.
How it works
Write each number as a product of primes. The GCD takes every prime the numbers share, each at its lowest power. The LCM takes every prime that appears in any number, each at its highest power.
GCD = product of common primes, lowest power
LCM = product of all primes, highest power
Two numbers: GCD × LCM = a × bExample
24 = 2³ × 3 and 36 = 2² × 3². Common primes at the lowest power: 2² × 3 = 12, so GCD = 12. Every prime at the highest power: 2³ × 3² = 72, so LCM = 72. Check: 12 × 72 = 864 = 24 × 36.
Common mistakes
- Using GCD × LCM = a × b for three or more numbers. That identity holds for two numbers only: for 2, 4 and 8 the GCD is 2 and the LCM is 8, so GCD × LCM = 16, but the product is 64.
- Taking the highest power for the GCD, or the lowest for the LCM. The GCD can never be larger than the smallest number, and the LCM can never be smaller than the largest.
- Dropping a prime from the LCM because only one number contains it. The LCM needs every prime that appears anywhere.
About this calculator
Type two or more whole numbers, separated by commas, spaces or new lines, and the calculator returns their greatest common divisor (also called the highest common factor, HCF) and their least common multiple. Underneath, it writes each number as a product of primes and shows which primes and powers make up the GCD and the LCM.
The GCD and LCM are worked out on exact integers (up to 60 digits per number, 20 numbers at a time). Prime factors are shown for numbers up to 1,000,000,000,000; larger numbers skip that step but still get an exact GCD and LCM. Negative numbers are used by their absolute value, and decimals are rejected because both measures only exist for integers.
Frequently asked questions
Are GCD and HCF the same thing?
Yes. GCD (greatest common divisor) and HCF (highest common factor) are two names for the largest whole number that divides every number in the list without a remainder. This calculator shows it under the heading GCD (HCF).
What is the difference between GCD and LCM?
The GCD is the largest number that divides all of them. The LCM is the smallest positive number that all of them divide into. For 24 and 36 the GCD is 12 and the LCM is 72.
How does it handle zero and negative numbers?
Negative numbers are replaced by their absolute value, because divisibility ignores sign. gcd(0, n) is n, since every number divides 0. The LCM of any list that contains 0 is 0, because 0 is the only common multiple of 0 and another number. gcd(0, 0) is taken as 0 by convention.
How large can the numbers be?
Each number can have up to 60 digits and you can enter up to 20 numbers. The GCD and LCM are exact at that size. The prime factorisation is only shown for numbers up to 1,000,000,000,000, because splitting larger numbers into primes by trial division would be slow.
Why are decimals not accepted?
GCD and LCM are defined for whole numbers. A decimal such as 2.5 is listed by name as unusable instead of being rounded. To simplify a ratio of decimals, use the ratio calculator, which scales them to whole numbers first.