GCD and LCM Calculator: Prime Factors and Euclid
By HesaplayıcıHow we calculate
The GCD and LCM calculator finds the greatest common divisor (GCD) and least common multiple (LCM) of between 2 and 10 positive whole numbers. Separate entries with spaces, commas, semicolons or line breaks to inspect every number’s prime factorization, the exact GCD and LCM, and Euclid’s division steps.
Worked example: GCD and LCM of 24 and 30
GCD (greatest common divisor)
6
- LCM (least common multiple)
- 120
- Count of numbers
- 2
Step by step
n₁ = product of its prime factors
24 = 2³ × 3 = 24
n₂ = product of its prime factors
30 = 2 × 3 × 5 = 30
GCD (greatest common divisor)
GCD = product of the common prime factors, each with its lowest power
GCD = 2 × 3 = 6
LCM (least common multiple)
LCM = product of all prime factors, each with its highest power
LCM = 2³ × 3 × 5 = 120
GCD(x, y) = GCD(y, x mod y)
GCD(24, 30): 30 = 1 × 24 + 6; 24 = 4 × 6 + 0 = 6
How GCD and LCM are calculated
The greatest common divisor (GCD) is the largest positive integer that divides every number in the list with no remainder. The least common multiple (LCM) is the smallest positive integer that is a multiple of every number in the list. Two equivalent methods are shown together:
- Prime factorization: Factor each integer into
n = p₁^e₁ × p₂^e₂ × ….GCD= product of primes shared by every number, using the lowest exponent of each.LCM= product of all primes present in at least one number, using the highest exponent of each.
- Euclid’s algorithm:
GCD(x, y) = GCD(y, x mod y)repeatedly replaces the larger number with the remainder until the remainder hits 0; the last nonzero divisor is the GCD. - Two-number identity:
n₁ × n₂ = GCD(n₁, n₂) × LCM(n₁, n₂)(for two numbers only).
Worked examples
1. Two numbers — 24 and 30:
- Prime factors:
24 = 2³ × 3¹and30 = 2¹ × 3¹ × 5¹. - GCD: Shared primes are
2and3→2¹ × 3¹ = 6. - LCM: All primes are
2,3,5→2³ × 3¹ × 5¹ = 120. - Euclid check:
30 = 24 × 1 + 6,24 = 6 × 4 + 0→ final divisor 6. - Product check:
24 × 30 = 720and6 × 120 = 720.
2. Three numbers — 12, 18 and 30: Factoring gives 12 = 2² × 3, 18 = 2 × 3² and 30 = 2 × 3 × 5. Taking minimum shared powers gives GCD = 2 × 3 = 6; taking maximum powers across all primes gives LCM = 2² × 3² × 5 = 180.
GCD or LCM? Quick decision guide
| Problem type | Use | Example |
|---|---|---|
| Splitting materials into the largest equal pieces | GCD | 24 m and 30 m ropes cut cleanly into 6 m segments |
| Reducing a fraction to lowest terms in one step | GCD | 84/126 divided by GCD = 42 gives 2/3 |
| Finding when repeating schedules coincide next | LCM | Shifts every 4 and 6 days align every 12 days |
| Finding a least common denominator to add fractions | LCM | 1/4 + 1/6 uses common denominator LCM(4, 6) = 12 |
Input rules and limits
Enter 2 to 10 positive integers (1 to 10¹²), or paste a spreadsheet column directly; zero, negatives and decimals are rejected. Results are exact integers; if the LCM exceeds 2⁵³ − 1 (9,007,199,254,740,991), the calculator reports an overflow error rather than rounding. To reduce fractions with the GCD use the simplify fractions calculator, or to simplify ratios use the ratio simplifier.
Frequently Asked Questions
What are the GCD and LCM of coprime (relatively prime) numbers?
Two numbers with no common factor greater than 1 have GCD = 1 and LCM equal to their product. For example, 25 and 18 are coprime, so GCD(25, 18) = 1 and LCM(25, 18) = 450.
What happens if one number divides the other evenly?
When one positive integer is a multiple of another, the GCD equals the smaller number and the LCM equals the larger number: GCD(4, 12) = 4 and LCM(4, 12) = 12.
When should I use GCD versus LCM in word problems?
Use GCD when splitting lengths, batches or rooms into the largest equal pieces with nothing left over, or when reducing fractions. Use LCM when finding when repeating cycles next align or when finding a least common denominator.
Does n₁ × n₂ = GCD × LCM hold for three or more numbers?
No—that identity holds only for two numbers. For 12, 18 and 30, the product is 6,480 while GCD × LCM = 6 × 180 = 1,080. For three to ten numbers, the calculator derives exact results from prime factorizations and pairwise Euclidean steps.
Calculation rules
- The GCD is the product of the prime factors that every number has, each with its lowest power; the LCM is the product of every prime factor of any number, each with its highest power. The calculator also finds the GCD with Euclid’s algorithm: both ways give the same result.
- Numbers must be whole numbers from 1 to 10¹². Results are exact and never rounded. When the LCM passes 9,007,199,254,740,991 (2⁵³ − 1), the calculator gives an error instead of a rounded number.
- For two numbers, GCD × LCM equals the product of the numbers. A GCD of 1 means the numbers are coprime.