GCD, LCM & Prime Factorization Calculator

GCD and LCM of two numbers

GCD and LCM of three numbers

Prime factorization

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

Greatest common divisor table
A \ B4691012162045
626326223
842124841
12463212443
15133531515
1826926229
24463212843
3026310621015
36469212449
For example, the GCD of 24 and 16 is 8.

Reference table

Least common multiple table
A \ B345671015
264106141030
3312156213015
41242012282060
51520530351015
6612306423030
824840245640120
99364518639045
1212126012846060
For example, the LCM of 4 and 6 is 12.

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.