GCD, LCM & Prime Factorization Calculator
GCD and LCM of two numbers
GCD
- LCM
GCD and LCM of three numbers
GCD
- LCM
Prime factorization
Prime factors
- Number of divisors
- Type
Your inputs are saved in the address. Bookmark the page (Ctrl+D) to come back to them.
The greatest common divisor (GCD) simplifies fractions and splits things into equal groups; the least common multiple (LCM) gives common denominators and tells you when two repeating schedules line up again. Enter two or three whole numbers to get both.
The prime factorization calculator writes a number as a product of prime powers and also shows how many divisors it has and whether it is prime.
How it works
The GCD comes from Euclid's algorithm: divide the larger number by the smaller, then keep dividing the previous divisor by the remainder until the remainder is 0. The last divisor is the GCD. For 18 and 12, 18 ÷ 12 leaves 6 and 12 ÷ 6 leaves 0, so the GCD is 6.
The LCM is the product of the two numbers divided by their GCD (A × B ÷ GCD). For three numbers, the result for the first two is combined with the third in the same way. Every digit is computed exactly, for inputs up to 15 digits.
Prime factorization tries dividing by 2, 3, 5, 7 and so on (trial division). Checking up to the square root of what is left is enough, so numbers up to one trillion (10¹²) finish quickly. The number of divisors is the product of each exponent plus one: 360 = 2³ × 3² × 5 has (3+1)(2+1)(1+1) = 24 divisors.
Only positive whole numbers are accepted. The number 1 has a single divisor, itself, so it is neither prime nor composite.
Worked examples
- GCD and LCM of two numbers
The greatest common divisor of 24 and 36 is 12 and their least common multiple is 72. - GCD and LCM of three numbers
The greatest common divisor of 12, 18 and 30 is 6 and their least common multiple is 180. - Prime factorization
360 = 2³ × 3² × 5. It has 24 divisors (Composite). - Prime factorization
1,001 = 7 × 11 × 13. It has 8 divisors (Composite).
Reference table
| A \ B | 4 | 6 | 9 | 10 | 12 | 16 | 20 | 45 |
|---|---|---|---|---|---|---|---|---|
| 6 | 2 | 6 | 3 | 2 | 6 | 2 | 2 | 3 |
| 8 | 4 | 2 | 1 | 2 | 4 | 8 | 4 | 1 |
| 12 | 4 | 6 | 3 | 2 | 12 | 4 | 4 | 3 |
| 15 | 1 | 3 | 3 | 5 | 3 | 1 | 5 | 15 |
| 18 | 2 | 6 | 9 | 2 | 6 | 2 | 2 | 9 |
| 24 | 4 | 6 | 3 | 2 | 12 | 8 | 4 | 3 |
| 30 | 2 | 6 | 3 | 10 | 6 | 2 | 10 | 15 |
| 36 | 4 | 6 | 9 | 2 | 12 | 4 | 4 | 9 |
Reference table
| A \ B | 3 | 4 | 5 | 6 | 7 | 10 | 15 |
|---|---|---|---|---|---|---|---|
| 2 | 6 | 4 | 10 | 6 | 14 | 10 | 30 |
| 3 | 3 | 12 | 15 | 6 | 21 | 30 | 15 |
| 4 | 12 | 4 | 20 | 12 | 28 | 20 | 60 |
| 5 | 15 | 20 | 5 | 30 | 35 | 10 | 15 |
| 6 | 6 | 12 | 30 | 6 | 42 | 30 | 30 |
| 8 | 24 | 8 | 40 | 24 | 56 | 40 | 120 |
| 9 | 9 | 36 | 45 | 18 | 63 | 90 | 45 |
| 12 | 12 | 12 | 60 | 12 | 84 | 60 | 60 |
FAQ
What does a GCD of 1 mean?
The two numbers share no common factor other than 1; they are called coprime. Their LCM is then simply their product.
How do I use the GCD to simplify a fraction?
Divide the numerator and the denominator by their GCD. 24/36 has a GCD of 12, so it simplifies to 2/3. To add fractions, use the LCM of the denominators as the common denominator.
Where is the LCM used in everyday life?
Whenever repeating events with different cycles need to line up. If one bus leaves every 4 days and another every 6 days, and both left today, they next leave on the same day in 12 days.
Why is factorization limited to one trillion?
Large primes need many trial divisions. Capping the input at 1,000,000,000,000 keeps the answer instant in your browser. GCD and LCM accept numbers up to 10¹⁵.
Why are zero and negative numbers not accepted?
GCD, LCM and prime factorization as taught in school are defined for positive whole numbers. For a negative number, drop the sign; the result is the same.