Ekuation

mode

GCD and LCM Calculator

Find the GCD and LCM of two integers using prime factorization with a Venn diagram.

Back to Prime Factorization Calculator

Enter a positive integer greater than 1

Optionally enter a second integer to compute GCD and LCM

Display the step-by-step trial division process

Prime Factorization Tips

Click to show tips

Try an Example

Pick a scenario to see how the calculator works, then adjust the values

Highly Composite Number

Factor 360, a highly composite number with many divisors.

Key values: 360 = 2^3 x 3^2 x 5 · 24 divisors · phi(360) = 96

Large Prime

Check if 7919 is prime (it is -- the 1000th prime number).

Key values: 7919 is prime · 2 divisors · phi(7919) = 7918

GCD and LCM

Compute the GCD and LCM of 84 and 120.

Key values: 84 = 2^2 x 3 x 7 · 120 = 2^3 x 3 x 5 · GCD = 12, LCM = 840

Documentation

GCD and LCM via Prime Factorization

Once you have the prime factorizations of two numbers, GCD and LCM follow directly:

gcd(a,b)=pmin(e,f)\gcd(a, b) = \prod p^{\min(e, f)}

Take each shared prime at the minimum exponent.

lcm(a,b)=pmax(e,f)\text{lcm}(a, b) = \prod p^{\max(e, f)}

Take every prime (from either number) at the maximum exponent.


The Fundamental Identity

gcd(a,b)×lcm(a,b)=a×b\gcd(a, b) \times \text{lcm}(a, b) = |a \times b|

This identity means you only need to compute one (GCD or LCM) and derive the other. Euclid's algorithm computes GCD in O(logmin(a,b))O(\log \min(a,b)) time without needing factorization.


Practical Examples

Simplifying Fractions

To simplify 48/180: factor 48=24×348 = 2^4 \times 3 and 180=22×32×5180 = 2^2 \times 3^2 \times 5. gcd=22×3=12\gcd = 2^2 \times 3 = 12. Divide both by 12: 48/180=4/1548/180 = 4/15.

Scheduling Problems

Two buses arrive every 12 and 18 minutes. When do they coincide? lcm(12,18)=36\text{lcm}(12, 18) = 36 minutes.

Gear Ratio Simplification

Gears with 24 and 36 teeth: gcd(24,36)=12\gcd(24, 36) = 12. Simplest ratio: 2:3.


Frequently Asked Questions

What is the difference between GCD and LCM?

The GCD (Greatest Common Divisor) is the largest number that divides both integers evenly. The LCM (Least Common Multiple) is the smallest positive number that both integers divide into evenly. For 12 and 18: GCD = 6, LCM = 36.

How do you find GCD using prime factorization?

Factor both numbers into primes, then take each shared prime at its minimum exponent. For example, 48=24×348 = 2^4 \times 3 and 180=22×32×5180 = 2^2 \times 3^2 \times 5. The shared primes are 2 and 3, so gcd=22×3=12\gcd = 2^2 \times 3 = 12.

How do you find LCM using prime factorization?

Factor both numbers into primes, then take every prime (from either number) at its maximum exponent. For 12=22×312 = 2^2 \times 3 and 18=2×3218 = 2 \times 3^2: lcm=22×32=36\text{lcm} = 2^2 \times 3^2 = 36.

What is the relationship between GCD and LCM?

For any two positive integers aa and bb, gcd(a,b)×lcm(a,b)=a×b\gcd(a, b) \times \text{lcm}(a, b) = a \times b. This identity lets you compute one from the other. For example, gcd(12,18)=6\gcd(12, 18) = 6 and lcm(12,18)=36\text{lcm}(12, 18) = 36, and 6×36=216=12×186 \times 36 = 216 = 12 \times 18.

When are two numbers coprime?

Two numbers are coprime (or relatively prime) when their GCD is 1, meaning they share no common prime factors. For example, 8 and 15 are coprime because 8=238 = 2^3 and 15=3×515 = 3 \times 5 share no primes. A fraction a/ba/b is already in lowest terms when aa and bb are coprime.

More Math Calculators

Explore the category

Calculator Search

Search and find calculators