Prime Factorization Calculator
Prime factors with division steps, a factor tree, the divisor count and every divisor.
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.
LCM(24, 36)
72
GCF (GCD): 12
The largest number that divides both 24 and 36 is 12, and the smallest positive number that both divide is 72.
| Step | a | b | Quotient q | Remainder r |
|---|---|---|---|---|
| 1 | 36 | 24 | 1 | 12 |
| 2 | 24 | 12 | 2 | 0 |
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.
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.
Division 1
Division 2
The remainder is 0, so stop.
Read off the GCD
The last non-zero remainder is 12.
Find the LCM from the GCD
Dividing the product by the GCD removes the shared factors once.
Bézout coefficients
Running Euclid’s algorithm backward (the extended Euclidean algorithm) writes the GCD as a combination of the two numbers.
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.
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.
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.
LCM from the GCF
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
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
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
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.
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 ( 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.
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.
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.
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.
| Numbers | LCM | GCF (GCD) |
|---|---|---|
| 3 and 4 | 12 | 1 |
| 4 and 6 | 12 | 2 |
| 6 and 8 | 24 | 2 |
| 8 and 12 | 24 | 4 |
| 12 and 15 | 60 | 3 |
| 12 and 18 | 36 | 6 |
| 12 and 48 | 48 | 12 |
| 15 and 20 | 60 | 5 |
| 18 and 24 | 72 | 6 |
| 24 and 32 | 96 | 8 |
| 24 and 36 | 72 | 12 |
| 30 and 54 | 270 | 6 |
| 625 and 1000 | 5000 | 125 |
| 1, 2, 3, …, 10 | 2520 | 1 |
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.
To add or subtract fractions, rewrite them over the least common denominator, which is the LCM of the denominators. For : lcm(12, 18) = 36, so and , and the sum is . 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 for fractions in lowest terms. For decimals, scale to whole numbers first: lcm(1.2, 1.8) = lcm(12, 18) ÷ 10 = 3.6.
Try these by hand, then type the numbers into the calculator to check your steps.
| Problem | Answer | Quickest method |
|---|---|---|
| LCM of 6 and 9 | 18 | List multiples of 9: 9, 18 |
| GCF of 30 and 45 | 15 | Prime factors: 2 × 3 × 5 and 3² × 5 share 3 × 5 |
| LCM of 4, 6 and 8 | 24 | Ladder: ÷ 2 gives 2, 3, 4; ÷ 2 gives 1, 3, 2; 2 × 2 × 1 × 3 × 2 = 24 |
| LCM of 14 and 15 | 210 | Coprime, so multiply: 14 × 15 |
| GCF of 84 and 126 | 42 | Euclid: 126 = 1 × 84 + 42, 84 = 2 × 42 + 0 |
| LCM of 84 and 126 | 252 | 84 × 126 ÷ 42 |
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, . 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.
Find lcm(24, 36) and gcd(24, 36) three ways, then write the GCF as a combination of 24 and 36.
Answer: lcm(24, 36) = 72 and gcd(24, 36) = 12, with .
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.
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.
Yes. Greatest common divisor (GCD), greatest common factor (GCF) and highest common factor (HCF) are three names for the same number.
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.
72. In primes, 24 = 2³ × 3 and 36 = 2² × 3², and the highest powers give 2³ × 3² = 72. Their GCF is 2² × 3 = 12.
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.
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 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.
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.
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.
Prime factors with division steps, a factor tree, the divisor count and every divisor.
Add, subtract, multiply, divide and simplify fractions and mixed numbers, with every step shown.
a mod n with steps, negative numbers, power mod and modular inverses.
Is it prime? Proof by smallest factor, next and previous primes, and a primes list for any range.
Factor a polynomial completely, with each step labeled by method and a check by expanding.
Free worked solutions for equations, systems, inequalities, factoring, derivatives, integrals, limits and matrices.
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?