LCM and GCD Calculator
LCM and GCD Calculator
Enter 2 to 10 positive whole numbers, separated by spaces or commas.
Enter two or more whole numbers to get the least common multiple (LCM) and the greatest common divisor (GCD) instantly — also called the greatest common factor (GCF) or highest common factor (HCF). The calculator shows the working with prime factorization, the ladder method and the Euclidean algorithm, so you can check homework or learn the method. Three, four or more numbers work too.
How to use the LCM and GCD calculator
- Type the numbers separated by spaces or commas, for example
12, 18or12 18 30– up to 10 numbers with up to 12 digits each. Then click Calculate or press Enter. - The GCD and LCM appear right away; click the icon to copy. If the GCD is 1, the numbers are marked as coprime.
- Under Calculation steps, switch between Prime factorization, Ladder method (short division) and Euclidean algorithm to see the full working.
- With exactly two numbers you also get a check: the product of the numbers = GCD × LCM.
What are the GCD and LCM?
- Factor: a whole number that divides another exactly. The factors of 12 are 1, 2, 3, 4, 6 and 12.
- Common factor: a factor shared by several numbers. The common factors of 12 and 18 are 1, 2, 3 and 6.
- Greatest common divisor (GCD / GCF / HCF): the largest common factor. The GCD of 12 and 18 is 6.
- Multiple: a number times 1, 2, 3 … The multiples of 12 are 12, 24, 36, 48 …
- Common multiple: a multiple shared by several numbers. Common multiples of 12 and 18 are 36, 72, 108 …
- Least common multiple (LCM): the smallest common multiple. The LCM of 12 and 18 is 36.
For small numbers you can simply list the factors and multiples. For larger numbers, or three or more numbers, the methods below are faster.
Three ways to find the GCD and LCM
All three methods below use 12 and 18 and give GCD = 6 and LCM = 36.
Method 1: Prime factorization
Write each number as a product of primes:
- 12 = 2² × 3
- 18 = 2 × 3²
Then compare the power of each prime:
| Prime | 12 | 18 | GCD: lower power | LCM: higher power |
|---|---|---|---|---|
| 2 | 2² | 2¹ | 2¹ | 2² |
| 3 | 3¹ | 3² | 3¹ | 3² |
- GCD = 2 × 3 = 6 – only primes that appear in every number, each with its lower power
- LCM = 2² × 3² = 36 – every prime, each with its higher power
Method 2: Ladder method (short division)
Divide both numbers by a common prime and keep going until they have no common factor left:
2 ) 12 18
───────
3 ) 6 9
───────
2 3
- GCD = the divisors on the left multiplied = 2 × 3 = 6
- LCM = the divisors on the left × the bottom row = 2 × 3 × 2 × 3 = 36
The ladder (also called the cake or box method) is the quickest way to work by hand once you know your primes.
Method 3: Euclidean algorithm
Divide the larger number by the smaller, then divide the divisor by the remainder, and repeat until the remainder is 0. The last divisor is the GCD:
- 18 = 1 × 12 + 6
- 12 = 2 × 6 + 0 → GCD = 6
Then LCM = product ÷ GCD: 12 × 18 ÷ 6 = 36.
The Euclidean algorithm shines with large numbers that are hard to factor, for example 1071 and 462:
- 1071 = 2 × 462 + 147
- 462 = 3 × 147 + 21
- 147 = 7 × 21 + 0 → GCD = 21, and LCM = 1071 × 462 ÷ 21 = 23562
GCD and LCM of three numbers
For 12, 18 and 30 the GCD is 6 and the LCM is 180. With three or more numbers, do the ladder separately for the GCD and the LCM.
For the GCD, divide only by a prime that divides all the numbers:
2 ) 12 18 30
────────────
3 ) 6 9 15
────────────
2 3 5
GCD = 2 × 3 = 6
For the LCM, keep dividing as long as a prime divides at least two of the numbers, and bring down any number it does not divide. Example: 4, 6 and 8:
2 ) 4 6 8
─────────
2 ) 2 3 4
─────────
1 3 2
In the second row 3 is not divisible by 2, so it is brought down unchanged. LCM = 2 × 2 × 1 × 3 × 2 = 24, while the GCD is just the first divisor, 2.
Common mistake: for two numbers, LCM = product ÷ GCD, but this does not work for three numbers. 12 × 18 × 30 ÷ 6 = 1080, yet the correct LCM is 180. Use the ladder, prime factorization (12 = 2² × 3, 18 = 2 × 3², 30 = 2 × 3 × 5, so LCM = 2² × 3² × 5 = 180), or find the LCM of the first two numbers and then of that result with the third.
GCD and LCM word problems
GCD: largest equal pieces, equal groups
- A 24 cm × 36 cm sheet is cut into equal squares with nothing left over. What is the largest possible square? → GCD(24, 36) = 12 cm, giving 2 × 3 = 6 squares.
- 18 apples and 24 oranges are shared equally with nothing left. What is the largest number of children? → GCD(18, 24) = 6 children, each getting 3 apples and 4 oranges.
LCM: happening together again, common denominators
- Bus A leaves every 12 minutes and bus B every 18 minutes. Both leave at 7:00 – when do they leave together again? → LCM(12, 18) = 36, so at 7:36.
- Adding fractions: the common denominator of 1/12 + 1/18 is the LCM 36, so 3/36 + 2/36 = 5/36.
Quick rule: if the problem is about splitting into the largest equal parts, it is usually the GCD; if it is about when things line up again, it is usually the LCM.
FAQ
How do you find the GCD and LCM?
The quickest hand method is the ladder: divide the numbers by common primes until none is left. The divisors on the left multiplied give the GCD; the divisors times the bottom row give the LCM. You can also use prime factorization (GCD takes the lower power of shared primes, LCM the higher power of all primes) or the Euclidean algorithm for the GCD.
How do you find the LCM of three numbers?
With the ladder, keep dividing as long as a prime divides at least two of the numbers, bring down the ones it does not divide, and multiply the divisors and the bottom row. For example, the LCM of 12, 18 and 30 is 180. Do not use “product ÷ GCD” for three numbers.
What are the GCD and LCM of two coprime numbers?
Coprime numbers share no factor other than 1, so their GCD is 1 and their LCM is their product. For example, 8 and 15 are coprime: GCD = 1 and LCM = 120.
How are the GCD and LCM related?
For two numbers, the product of the numbers equals GCD × LCM. For example, 12 × 18 = 216 = 6 × 36. So once you know the GCD, the LCM is the product divided by the GCD. This only holds for two numbers.
Are GCD, GCF and HCF the same thing?
Yes. Greatest common divisor (GCD), greatest common factor (GCF) and highest common factor (HCF) are three names for the same number. GCF is common in US schools, HCF in the UK and India, and GCD in higher maths and programming.
- Prime Factorization Calculator: break a number into its prime factors.
- Standard Deviation Calculator: mean, variance and standard deviation.
- Random Number Generator: pick random numbers in any range.