Number Theory & Bases

LCM and GCF Calculator

This LCM calculator finds the least common multiple (LCM) and the greatest common factor (GCF), also called the GCD, of 2 to 10 whole numbers, with steps.

Try

Separate the numbers with commas or spaces. Negative numbers and 0 are allowed, up to 40 digits each.

Result

LCM(24, 36): 72

LCM(24, 36)

72

GCF (GCD): 12

Greatest common factor (GCF or GCD)
12
Coprime?
No: both are divisible by 12
Bézout identityFrom the extended Euclidean algorithm
12=24⋅(−1)+36⋅112 = 24 \cdot \left(-1\right) + 36 \cdot 1
GCD × LCMAlways equals |a × b|
12 × 72 = 864
Ratio in lowest terms
2 : 3
Prime factorizations
24 = 2³ × 3; 36 = 2² × 3²
All common divisorsThe common divisors are exactly the divisors of the GCD
1, 2, 3, 4, 6, 12

The largest number that divides both 24 and 36 is 12, and the smallest positive number that both divide is 72.

Euclid’s algorithm for 24 and 36
StepabQuotient qRemainder r
13624112
2241220
Step-by-step working (9 steps)
  1. List multiples of the largest number

    Multiples of 36: 36, 72. The first one is divisible by every number in the list, so the LCM is 72.

  2. Start Euclid’s algorithm

    Divide the larger absolute value by the smaller and keep the remainder. Then divide the previous divisor by that remainder, and repeat until the remainder is 0.

  3. Division 1

    36=1⋅24+1236 = 1 \cdot 24 + 12
  4. Division 2

    The remainder is 0, so stop.

    24=2⋅12+024 = 2 \cdot 12 + 0
  5. Read off the GCD

    The last non-zero remainder is 12.

    gcd(24,36)=12\gcd(24, 36) = 12
  6. Find the LCM from the GCD

    Dividing the product by the GCD removes the shared factors once.

    lcm(24,36)=|24⋅36|12=86412=72\operatorname{lcm}(24, 36) = \frac{|24 \cdot 36|}{12} = \frac{864}{12} = 72
  7. Bézout coefficients

    Running Euclid’s algorithm backward (the extended Euclidean algorithm) writes the GCD as a combination of the two numbers.

    12=24⋅(−1)+36⋅112 = 24 \cdot \left(-1\right) + 36 \cdot 1
  8. Check with the division (ladder) method

    Divide by a prime that goes into at least two numbers and bring the others down: ÷ 2 gives 12, 18; ÷ 2 gives 6, 9; ÷ 3 gives 2, 3. No two numbers left share a prime, so multiply the divisors and the bottom row: 2 × 2 × 3 × 2 × 3 = 72.

  9. Check with prime factorizations

    The GCD takes each prime shared by all the numbers to its lowest power: 2² × 3 = 12. The LCM takes every prime to its highest power: 2³ × 3² = 72.

    24=23⋅3,36=22⋅3224 = 2^{3} \cdot 3,\quad 36 = 2^{2} \cdot 3^{2}

The LCM of two numbers is their product divided by their GCF, which comes from Euclid’s algorithm. Example: the LCM of 24 and 36 is 72 and their GCF is 12.

By Hira Noor, mathematicianLast reviewed Free, no sign-up, runs in your browserReport a problem

How to use this calculator

  1. Type the numbers separated by commas or spaces, for example 24, 36 or 12 18 30. You can enter up to 10 numbers.
  2. Negative numbers and 0 are allowed. Do not use thousands separators here, because commas separate the numbers.
  3. Read the LCM at the top and the GCF (GCD) under it. For two numbers, the table shows every division in Euclid’s algorithm.
  4. Open the steps to see the multiples, the LCM formula, the Bézout identity and the prime-factorization check.

Formulas

LCM from the GCF

lcm(a,b)=|a⋅b|gcd(a,b)\operatorname{lcm}(a, b) = \frac{|a \cdot b|}{\gcd(a, b)}

Plain-text formula: lcm(a, b) = (|a · b|)/(gcd(a, b))

Dividing the product by the GCF removes the factors the two numbers share, so they are counted once. For more than two numbers, apply it repeatedly: lcm(a, b, c) = lcm(lcm(a, b), c).

Using prime factorizations

gcd=∏pmin(ei),lcm=∏pmax(ei)\gcd = \prod p^{\min(e_i)},\qquad \operatorname{lcm} = \prod p^{\max(e_i)}

Plain-text formula: gcd = ∏p^(min(e_i)), lcm = ∏p^(max(e_i))

For the LCM, take every prime that appears in any number, to the highest power it appears. For the GCF, take only the primes shared by all the numbers, to the lowest power.

Euclid’s algorithm

a=qb+r,0≤r<b;⇒;gcd(a,b)=gcd(b,r)a = q b + r,\quad 0 \le r < b ;\Rightarrow; \gcd(a, b) = \gcd(b, r)

Plain-text formula: a = qb + r, 0 ≤ r < b; ⇒ ; gcd(a, b) = gcd(b, r)

Any common divisor of a and b also divides r = a − qb, so replacing (a, b) by (b, r) keeps the GCF. The numbers shrink quickly, and when the remainder reaches 0 the last divisor is the GCF.

Bézout’s identity

gcd(a,b)=ax+by\gcd(a, b) = a x + b y

Plain-text formula: gcd(a, b) = ax + by

Integers x and y with this property always exist; the extended Euclidean algorithm finds them. They are used to compute modular inverses and to solve equations such as 24x + 36y = 12.

Reading the result

The LCM is the smallest positive number that all of your numbers divide. It is the least common denominator when you add fractions, and it tells you when repeating cycles line up again: two lights flashing every 12 and 18 seconds flash together every 36 seconds.

The GCF (greatest common factor, also called the greatest common divisor or highest common factor) is the largest whole number that divides all of your numbers. Use it to simplify fractions (2436=23\frac{24}{36} = \frac{2}{3} after dividing by 12) or to split things into the largest equal groups. If the GCF is 1, the numbers are coprime and their LCM is simply their product.

For several numbers, being coprime as a set is weaker than being pairwise coprime: 6, 10 and 15 have GCF 1, yet each pair shares a factor.

How to find the LCM: 4 methods

1. List the multiples. Write out multiples of the largest number and stop at the first one the other numbers divide. For 4 and 6: multiples of 6 are 6, 12, … and 12 ÷ 4 = 3, so the LCM is 12. Best for small numbers.

2. Prime factorization. Factor each number into primes, then multiply each prime at its highest power. 12 = 2² × 3 and 18 = 2 × 3², so lcm(12, 18) = 2² × 3² = 36. Best when you can factor the numbers easily, and it gives the GCF at the same time.

3. Division (ladder or cake) method. Write the numbers in a row and divide by a prime that goes into at least two of them, bringing down any number it does not divide. Repeat until no two numbers share a prime. The LCM is the product of the divisors on the side and the numbers left at the bottom. For 12, 18 and 30: divide by 2 to get 6, 9, 15; by 3 to get 2, 3, 5; so the LCM is 2 × 3 × 2 × 3 × 5 = 180. Best for three or more numbers by hand.

4. Use the GCF. Find the GCF with Euclid’s algorithm, then divide the product by it: lcm(24, 36) = 24 × 36 ÷ 12 = 72. Best for large numbers, and it is what this calculator uses.

Which to choose: listing works when the LCM is under about 100. Prime factors are clearest on paper for two or three numbers. For large or hard-to-factor numbers, use the GCF formula, since Euclid’s algorithm never needs a factorization.

How to find the GCF (GCD)

List the factors: the factors of 24 are 1, 2, 3, 4, 6, 8, 12, 24 and those of 36 are 1, 2, 3, 4, 6, 9, 12, 18, 36. The largest one on both lists is 12.

Prime factors: multiply the shared primes at their lowest power. 24 = 2³ × 3 and 36 = 2² × 3², so the GCF is 2² × 3 = 12.

Euclid’s algorithm: divide the larger number by the smaller and keep the remainder, then repeat with the divisor and the remainder: 36 = 1 × 24 + 12, then 24 = 2 × 12 + 0. The last non-zero remainder, 12, is the GCF. This is the fastest method for big numbers, and it is how this page works as a GCD calculator for integers up to 40 digits long.

LCM and GCF of common number pairs

Answers for pairs people often look up. GCF × LCM always equals the product of the two numbers, which is a quick way to check a row.

LCM and GCF of common pairs
NumbersLCMGCF (GCD)
3 and 4121
4 and 6122
6 and 8242
8 and 12244
12 and 15603
12 and 18366
12 and 484812
15 and 20605
18 and 24726
24 and 32968
24 and 367212
30 and 542706
625 and 10005000125
1, 2, 3, …, 1025201

Word problem: when do two schedules line up?

Problem: one bus leaves the station every 12 minutes and another every 18 minutes. Both leave at 8:00. When do they next leave together?

Solution: they leave together after a number of minutes that is a multiple of both 12 and 18, and the first such time is lcm(12, 18) = 36. They next leave together at 8:36, then every 36 minutes after that.

The same reasoning answers questions about gears returning to their starting position, planets lining up, or buying hot dogs in packs of 10 and buns in packs of 8 so none are left over (lcm(10, 8) = 40, so 4 packs of hot dogs and 5 packs of buns). A question about splitting things into the largest equal groups needs the GCF instead.

LCM of fractions and the least common denominator

To add or subtract fractions, rewrite them over the least common denominator, which is the LCM of the denominators. For 512+718\frac{5}{12} + \frac{7}{18}: lcm(12, 18) = 36, so 512=1536\frac{5}{12} = \frac{15}{36} and 718=1436\frac{7}{18} = \frac{14}{36}, and the sum is 2936\frac{29}{36}. The fraction calculator does this for you.

The LCM of the fractions themselves, the smallest positive number that each fraction divides a whole number of times, is lcm(ab,cd)=lcm(a,c)gcd(b,d)\operatorname{lcm}\left(\frac{a}{b}, \frac{c}{d}\right) = \frac{\operatorname{lcm}(a, c)}{\gcd(b, d)} for fractions in lowest terms. For decimals, scale to whole numbers first: lcm(1.2, 1.8) = lcm(12, 18) ÷ 10 = 3.6.

Practice problems with answers

Try these by hand, then type the numbers into the calculator to check your steps.

LCM and GCF practice
ProblemAnswerQuickest method
LCM of 6 and 918List multiples of 9: 9, 18
GCF of 30 and 4515Prime factors: 2 × 3 × 5 and 3² × 5 share 3 × 5
LCM of 4, 6 and 824Ladder: ÷ 2 gives 2, 3, 4; ÷ 2 gives 1, 3, 2; 2 × 2 × 1 × 3 × 2 = 24
LCM of 14 and 15210Coprime, so multiply: 14 × 15
GCF of 84 and 12642Euclid: 126 = 1 × 84 + 42, 84 = 2 × 42 + 0
LCM of 84 and 12625284 × 126 ÷ 42

Properties of the LCM and GCF

The LCM is never smaller than the largest number, and the GCF is never larger than the smallest (ignoring 0).

The LCM equals the product of two numbers exactly when they are coprime: lcm(8, 9) = 72.

The LCM equals the larger number when the smaller one divides it: lcm(12, 48) = 48, and then the GCF is the smaller number, 12.

For two numbers, gcd(a,b)⋅lcm(a,b)=|ab|\gcd(a, b) \cdot \operatorname{lcm}(a, b) = |ab|. This does not hold for three or more numbers: for 2, 4 and 8 the GCF is 2 and the LCM is 8, but 2 × 8 is not 64.

Worked example

LCM and GCF of 24 and 36

Find lcm(24, 36) and gcd(24, 36) three ways, then write the GCF as a combination of 24 and 36.

  1. Listing multiples of 36: 36, 72. 36 is not divisible by 24, but 72 = 3 × 24, so the LCM is 72.
  2. Prime factors: 24 = 2³ × 3 and 36 = 2² × 3². The LCM takes the highest powers, 2³ × 3² = 72. The GCF takes the lowest, 2² × 3 = 12.
  3. Euclid’s algorithm: 36 = 1 × 24 + 12, then 24 = 2 × 12 + 0. The last non-zero remainder is 12.
  4. Check with the formula: 24×3612=86412=72\frac{24 \times 36}{12} = \frac{864}{12} = 72.
  5. Working backward from the first division: 12 = 36 − 1 × 24.

Answer: lcm(24, 36) = 72 and gcd(24, 36) = 12, with 12=24⋅(−1)+36⋅112 = 24 \cdot (-1) + 36 \cdot 1.

Frequently asked questions

How do I calculate the LCM?

List the multiples of the largest number until you reach one the other numbers divide, or multiply each prime at its highest power from the prime factorizations. For two numbers you can also divide their product by the GCF: lcm(12, 18) = 216 ÷ 6 = 36.

What is the difference between GCF and LCM?

The GCF is the largest number that divides all the inputs; the LCM is the smallest positive number that all the inputs divide. For 12 and 18, the GCF is 6 and the LCM is 36.

Is GCD the same as GCF or HCF?

Yes. Greatest common divisor (GCD), greatest common factor (GCF) and highest common factor (HCF) are three names for the same number.

What is the LCM of 12 and 48?

48. Because 12 divides 48 (48 = 4 × 12), 48 is already a multiple of both, and no smaller positive number is a multiple of 48. Their GCF is 12.

What is the LCM of 24 and 36?

72. In primes, 24 = 2³ × 3 and 36 = 2² × 3², and the highest powers give 2³ × 3² = 72. Their GCF is 2² × 3 = 12.

What is the LCM of the numbers 1 to 10?

2520. It is the product of the highest prime powers up to 10: 2³ × 3² × 5 × 7 = 8 × 9 × 5 × 7 = 2520, the smallest number that 1, 2, 3, …, 10 all divide.

How do I find the LCM of 3 numbers?

Work in pairs: lcm(12, 18, 30) = lcm(lcm(12, 18), 30) = lcm(36, 30) = 180. You can also use the ladder method or take each prime at its highest power: 2² × 3² × 5 = 180. The GCF works the same way: gcd(12, 18, 30) = 6.

When is the LCM just the two numbers multiplied?

When the numbers are coprime, meaning their GCF is 1. For 8 and 9 the LCM is 8 × 9 = 72. If they share a factor, the product counts it twice, so the LCM is smaller.

What is the GCF or LCM of a number and 0?

gcd(a, 0) = |a|, because every number divides 0, so the common divisors are just the divisors of a. The LCM of any number and 0 is 0, since 0 is the only multiple of 0.

Why is Euclid’s algorithm so fast?

The remainder at least halves every two steps, so the number of divisions grows only with the number of digits. Consecutive Fibonacci numbers are the slowest case: 832040 and 514229 need 28 divisions.

Fraction Calculator

Add, subtract, multiply, divide and simplify fractions and mixed numbers, with every step shown.

Arithmetic & Numbers

Mod Calculator

a mod n with steps, negative numbers, power mod and modular inverses.

Number Theory & Bases

Factoring Calculator

Factor a polynomial completely, with each step labeled by method and a check by expanding.

Algebra & Equations

Step-by-Step Math Solver

Free worked solutions for equations, systems, inequalities, factoring, derivatives, integrals, limits and matrices.

Tools

Sources and further reading

  1. Prime Factorization and the Least Common Multiple (Section 2.5, Prealgebra 2e) (opens in a new tab), OpenStax, Rice University
  2. Euclid’s Elements, Book VII, Propositions 1 and 2 (opens in a new tab), Clark University (D. E. Joyce)
  3. The Art of Computer Programming, Vol. 2: Seminumerical Algorithms (§4.5.2), Addison-Wesley (Donald E. Knuth, 1997)

Results are calculated in your browser with methods checked by automated tests, and are intended for learning and general use. For engineering, medical, financial, legal or safety-critical decisions, verify important values independently and follow the rounding rules your work requires. How accurate are these results?