DigitHelm

GCD & LCM Calculator | Up to 10 Numbers

Find the GCD and LCM of up to 10 integers using the Euclidean algorithm. Shows prime factorization, divisibility check, and full step-by-step working.

Quick presets

What Is the GCD & LCM Calculator | Up to 10 Numbers?

The Greatest Common Divisor (GCD) of two or more integers is the largest positive integer that divides all of them without remainder. The Least Common Multiple (LCM) is the smallest positive integer that is a multiple of all input values. These two numbers are fundamentally linked by the identity GCD(a,b) × LCM(a,b) = |a × b| for any two integers.

This calculator uses the Euclidean algorithm, one of the oldest known algorithms, proven by Euclid around 300 BCE, to compute GCD efficiently in O(log min(a,b)) steps. LCM is then derived from GCD using the identity above. For multiple numbers, the algorithm is applied iteratively: GCD(a, b, c) = GCD(GCD(a, b), c).

The calculator also shows prime factorization of each input, which provides an alternative verification path: the GCD uses the minimum exponent of each shared prime, and the LCM uses the maximum exponent of every prime that appears. All calculations run in the browser, no data is sent to any server.

Formula

Euclidean Algorithm & LCM
GCD(a, b) = GCD(b, a mod b)
LCM(a, b) = |a × b| / GCD(a, b)
Identity: GCD(a,b) × LCM(a,b) = |a × b|
Multi-number extension
GCD of 3+ numbersGCD(a,b,c) = GCD(GCD(a,b), c)
LCM of 3+ numbersLCM(a,b,c) = LCM(LCM(a,b), c)
Via prime factorizationGCD: lowest powers of common primes
Via prime factorizationLCM: highest powers of all primes

How to Use

  1. 1Select a mode: Choose GCD & LCM (both), GCD only, or LCM only using the mode tabs at the top.
  2. 2Load a preset (optional): Click any preset, Simplify 48, 36; Calendar (7, 30, 365); Fractions (12, 18); or Large numbers (1234, 5678), to populate the input instantly.
  3. 3Enter your integers: Type 2 to 10 non-zero integers separated by commas, spaces, or both. Negative numbers are treated as their absolute values. Decimals are not allowed.
  4. 4Press Calculate: Click Calculate or press Enter to compute. Results appear below with the GCD, LCM, and product.
  5. 5Check prime factorizations: A table shows each number broken into prime factors in exponential notation, useful for understanding why the GCD and LCM have the values they do.
  6. 6Verify divisibility: The divisibility check panel shows which input numbers divide evenly into the LCM and what the result of LCM / n is.
  7. 7Expand step-by-step working: Click "Step-by-step working" to see the full Euclidean algorithm trace with division-with-remainder steps for GCD, and LCM derivation steps.
  8. 8Reset and try again: Press Reset or Esc to clear all fields and start over with new numbers.

Example Calculation

Example 1, Simplifying a fraction (48, 36)

GCD(48, 36): 48 = 36×1 + 12

36 = 12×3 + 0  → GCD = 12

LCM = 48 × 36 / 12 = 144

48/36 simplified: divide both by GCD(12) → 4/3

Prime factors: 48 = 2^4 × 3,  36 = 2^2 × 3^2

GCD: 2^min(4,2) × 3^min(1,2) = 2^2 × 3 = 12 (verified)

Example 2, Calendar scheduling (7, 30, 365)

Question: In how many days do weekly, monthly, and yearly events coincide?

GCD(7, 30) = 1  → GCD(1, 365) = 1

LCM(7, 30) = 210  → LCM(210, 365) = 76650

Answer: All three align every 76,650 days (about 209.7 years)

GCD = 1 means no common factor, the periods are mutually coprime

Example 3, Adding fractions (12, 18)

To add 5/12 + 7/18 we need the LCD = LCM(12, 18):

GCD(12, 18): 18 = 12×1 + 6; 12 = 6×2 + 0 → GCD = 6

LCM = 12 × 18 / 6 = 36

5/12 + 7/18 = 15/36 + 14/36 = 29/36

Understanding GCD & LCM | Up to 10 Numbers

GCD and LCM in Number Theory

The GCD and LCM are foundational to elementary number theory and have been studied for over 2,300 years. Euclid's algorithm for computing GCD appears in Book VII of the Elements (c. 300 BCE) and is one of the oldest algorithms still in active use in modern computing. Every modern programming language has a GCD function built on this algorithm.

The Euclidean Algorithm in Detail

The key insight behind the Euclidean algorithm is that GCD(a, b) = GCD(b, a mod b). This follows from the fact that any common divisor of a and b must also divide a − k×b for any integer k, so it must divide the remainder. The algorithm terminates because the remainder strictly decreases at every step, and a non-negative integer cannot decrease forever without reaching zero.

  • Time complexity: O(log min(a, b)) — extremely fast even for large numbers. Computing GCD(10^18, 10^18−1) takes fewer than 90 steps.
  • Binary GCD: A variant using only bit shifts and subtraction, better suited for hardware without a division instruction. Produces the same result.
  • Extended Euclidean: A version that also computes Bézout coefficients (integers x, y such that ax + by = GCD(a,b)), used in modular inverse computations for cryptography.

Why LCM Uses the GCD Formula

The identity LCM(a,b) = |a×b| / GCD(a,b) avoids computing LCM directly from the definition (which would require testing all multiples). Direct computation from prime factorizations is another option but requires full factorization, slower for large numbers. The GCD-based formula runs in the same time as computing the GCD itself.

Applications in Everyday Mathematics

  • Simplifying fractions: Divide numerator and denominator by GCD to reach lowest terms. The fraction calculator on this site uses exactly this method.
  • Finding a common denominator: LCD = LCM of all denominators. Using LCM rather than the product of all denominators keeps numbers manageable.
  • Tiling problems: The largest square tile that can cover an m×n floor without cutting = GCD(m,n) metres on a side.
  • Gear and rhythm synchronization: Two gears with tooth counts a and b return to their starting relative position every LCM(a,b) teeth — equivalent to scheduling repeated events.
  • Modular arithmetic: GCD determines if a linear congruence ax ≡ b (mod n) has solutions (it does iff GCD(a,n) | b).

Frequently Asked Questions

What is the Euclidean algorithm and how does it work?

The Euclidean algorithm computes GCD by repeatedly applying division with remainder. At each step, the larger number is replaced by the remainder of dividing the two numbers. The process continues until the remainder is zero, at which point the other number is the GCD.

  • • Step 1: GCD(48, 36) → 48 = 36×1 + 12
  • • Step 2: GCD(36, 12) → 36 = 12×3 + 0
  • • Remainder is 0, so GCD = 12

The algorithm is guaranteed to terminate because the remainder strictly decreases at each step. Its time complexity is O(log min(a, b)).

What is the relationship between GCD and LCM?

For any two integers a and b, the following identity always holds:

GCD(a,b) × LCM(a,b) = |a × b|

This means once you know the GCD, computing the LCM requires just one multiplication and one division. This identity does not generalize directly to three or more numbers, which is why LCM(a,b,c) must be computed iteratively.

What does a GCD of 1 mean (coprime numbers)?

When GCD(a, b) = 1, the numbers are called coprime (or relatively prime). They share no common prime factors. Examples:

  • • GCD(7, 13) = 1, both prime, so trivially coprime
  • • GCD(8, 9) = 1, 8 = 2^3, 9 = 3^2, no shared primes
  • • GCD(35, 64) = 1, 35 = 5×7, 64 = 2^6, no shared primes

Coprime numbers play a central role in RSA encryption, modular arithmetic, and Chinese Remainder Theorem.

How do I use GCD to simplify fractions?

Divide both numerator and denominator by their GCD:

a/b simplified = (a/GCD) / (b/GCD)

Example: 48/36 → GCD(48, 36) = 12 → 48/12 = 4, 36/12 = 3 → simplified = 4/3

The result is in lowest terms when GCD(numerator, denominator) = 1.

How do I use LCM to add fractions?

The Least Common Denominator (LCD) for adding fractions is the LCM of all denominators:

  • • To add 1/4 + 1/6: LCD = LCM(4,6) = 12
  • • Convert: 3/12 + 2/12 = 5/12

Using LCM rather than the product of denominators keeps numbers smaller and avoids the need to simplify afterwards.

Can GCD or LCM be computed for more than 2 numbers?

Yes. For any list of integers, apply the operation iteratively:

GCD(a,b,c) = GCD(GCD(a,b), c)

This calculator supports up to 10 numbers simultaneously. The result is the same regardless of the order you process the numbers (the operations are both commutative and associative).

What are practical applications of GCD and LCM?

GCD and LCM appear across mathematics, computer science, and real life:

  • Fractions: simplification (GCD) and common denominators (LCM)
  • Scheduling: finding when periodic events next coincide (LCM)
  • Gear ratios: computing exact tooth ratios that repeat cleanly
  • Cryptography: RSA relies on GCD for key generation and primality
  • Music: finding common time bases for polyrhythms

Why does the calculator show prime factorizations?

Prime factorization offers an independent verification route and deeper insight:

  • • GCD = product of primes with their minimum exponent across all inputs
  • • LCM = product of primes with their maximum exponent across all inputs
  • • Example: 12 = 2^2×3, 18 = 2×3^2 → GCD = 2^1×3^1 = 6, LCM = 2^2×3^2 = 36

Related Calculators