GCD & LCM
calculator.
Get the greatest common divisor and least common multiple of up to 10 whole numbers.
- GCD
- 12
- LCM
- 144
- Share a factor?
- Yes
12 is the largest number that divides both. Dividing by it gives 4 and 3, so 48 over 36 reduces to 4 over 3. 144 is the first number both go into.
Shared prime factors make the GCD
48 = 2⁴ × 3 and 36 = 2² × 3². The GCD takes each prime to its smallest power, 2² × 3 = 12, and the LCM takes each to its largest, 2⁴ × 3² = 144.
Each prime, smallest power and largest power
| Prime | In your numbers | GCD | LCM |
|---|---|---|---|
| 2 | 2⁴, 2² | 2² | 2⁴ |
| 3 | 3, 3² | 3 | 3² |
Working
- 1Divide the larger number by the smaller and keep the remainder48 = 1 × 36 + 12
- 2Repeat with the smaller number and the remainder until it is 036 = 3 × 12 + 0
- 3The last remainder before 0 is the GCDgcd = 12
- 4The LCM is the product divided by the GCDlcm =48 × 3612=1,72812= 144
- 5Check: each number divided by the GCD is whole48 ÷ 12 = 4, 36 ÷ 12 = 3
- 6Check: the LCM divided by each number is whole144 ÷ 48 = 3, 144 ÷ 36 = 4
- 7Check: for two numbers, GCD × LCM is their product12 × 144 = 1,728 = 48 × 36
Dividing 48 by 36
| Remainder | Quotient | x | y |
|---|---|---|---|
| 48 | 1y 0 | 0 | |
| 36 | 0y 1 | 1 | |
| 12quotient 1 | 1 | 1y −1 | −1 |
| 0quotient 3 | 3 | −3y 4 | 4 |
Each row is the one two above minus the quotient times the one above. The last nonzero remainder is the GCD, and its x and y give 48 × 1 + 36 × −1 = 12.
Many lists at once
GCD and LCM for each line
| Numbers | GCD | LCM |
|---|---|---|
| 12, 18 | 6 | 36 |
| 8, 9 | 1 | 72 |
| 24, 36, 60 | 12 | 360 |
| 7, 30, 365 | 1 | 15,330 |
How it's worked out
The greatest common divisor (GCD) is the largest whole number that divides every number in your list. You may know it as the greatest common factor (GCF) or the highest common factor (HCF). The least common multiple (LCM) is the smallest positive number that every number in the list divides into.
The GCD comes from Euclid's method, now called the Euclidean algorithm. Divide the larger number by the smaller and keep the remainder. Then divide the smaller number by that remainder, and go on until the remainder is 0. The last remainder before 0 is the GCD. For 1,071 and 462 the rows are 1,071 = 2 × 462 + 147, then 462 = 3 × 147 + 21, then 147 = 7 × 21 + 0, so the GCD is 21.
For two positive numbers, the LCM follows from the GCD. The Handbook of Applied Cryptography gives it as the product divided by the GCD (Fact 2.89). With more numbers, the tool folds them in one at a time, so the LCM of three numbers is the LCM of the first two, taken again with the third.
Prime factors give the same answers. Write each number as a product of primes. The GCD takes each prime the numbers share, at its smallest power. The LCM takes every prime, at its largest power. 48 = 2⁴ × 3 and 36 = 2² × 3², so the GCD is 2² × 3 = 12 and the LCM is 2⁴ × 3² = 144. OpenStax Prealgebra lines the primes up in columns to do the same thing by hand.
The same divisions also give two whole numbers x and y with a × x + b × y equal to the GCD. This is the extended Euclidean algorithm. The handbook's own example is 4,864 and 3,458, where 4,864 × 32 + 3,458 × (−45) = 38. The same pair of numbers is what a modular inverse needs.
Worked examples
Nadia reduces 48 over 36
Nadia's answer to a homework problem is 48 over 36, and the teacher wants it in lowest terms. The GCD of 48 and 36 is 12, so she divides the top and the bottom by it.
The new top and bottom, 4 and 3, share no factor, which is how she knows she is done. Dividing by a smaller common factor, such as 6, would leave a fraction that still reduces.
Finding a common denominator for a quarter and a sixth
To add a quarter and a sixth, Omar needs a bottom number that both 4 and 6 divide. The LCM is 12. That is 3 fours and 2 sixes.
Multiplying the two bottoms would give 24 instead. That works too, but the tops get larger and the answer needs reducing at the end.
When do three schedules line up again?
A weekly meeting, a 30-day billing cycle and a yearly review all fall on the same day today. They next fall together after the LCM of 7, 30 and 365, which is 15,330 days.
That is 42 cycles of 365 days, so the answer is decades away. The GCD of the three is 1: 30 and 365 share a 5, but 7 shares nothing with either.
Reading your result
A GCD of 1 means coprime. The numbers share no prime factor, though neither has to be prime: 8 and 9 have a GCD of 1. For two coprime numbers the LCM is just their product, here 72.
GCD times LCM equals the product only for two numbers. For 48 and 36, 12 × 144 = 1,728, the same as 48 × 36. For 2, 4 and 8 the GCD is 2 and the LCM is 8, and their product is far below 2 × 4 × 8.
Signs and zeros. A negative number is treated by its size, so the GCD of −12 and 18 is 6. Every number divides 0, so the GCD of 0 and 15 is 15, while any list with a 0 has an LCM of 0. A list of only zeros has no GCD, and the tool says so.
Large numbers stay exact. The Euclidean algorithm never needs to factor, so it is quick even for 40-digit numbers. Two numbers next to each other always have a GCD of 1, so the LCM of 1,000,000,000,000 and 999,999,999,999 is their product, 999,999,999,999,000,000,000,000. That is far past 2⁵³, where ordinary decimal arithmetic starts to round, so every step here uses whole numbers. Prime factors are listed only when every number is at most 10¹².
Common mistakes
- Mixing up the two rules. The GCD takes the smallest power of each shared prime; the LCM takes the largest power of every prime. Using the largest power for the GCD gives a number that does not divide your list.
- Using the GCD for a "when do they meet" question. Buses, cycles and repeating events line up at the LCM. The GCD answers "what is the largest equal group".
- Stopping at a common factor that is not the greatest. Dividing 48 and 36 by 6 leaves two numbers that are both still even, so the fraction is not in lowest terms yet.
- Extending the product rule to three numbers. GCD × LCM = a × b holds for a pair only, as the 2, 4 and 8 case shows.
- Calling numbers coprime only when they are prime. 8 and 9 are coprime, and 6 and 9 are not, though 9 is not prime in either pair.