Math

GCD & LCM Calculator

Calculate the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) with complete Euclidean algorithm steps. Supports two or more numbers.

Did this calculator help you?

What is GCD & LCM Calculator?

The Greatest Common Divisor (GCD) and Least Common Multiple (LCM) are two of the most important concepts in elementary number theory, with applications from simplifying fractions in middle school to cryptographic algorithms that secure the internet. The Euclidean algorithm, described by Euclid around 300 BC, is one of the oldest and most efficient algorithms in mathematics. It computes the GCD in O(log(min(a,b))) steps, terminating rapidly even for very large numbers. The algorithm applies the identity: GCD(a, b) = GCD(b, a mod b) repeatedly until the remainder is zero. This calculator shows the complete Euclidean algorithm step by step for two numbers, and also computes GCD and LCM for lists of multiple numbers using the generalization: GCD(a, b, c) = GCD(GCD(a, b), c).

When to Use This Calculator

  • Simplifying fractions to lowest terms: divide numerator and denominator by GCD
  • Adding or subtracting fractions with different denominators: find LCM of denominators
  • Scheduling problems: determining when two periodic events will next coincide
  • RSA cryptography: verifying that the encryption exponent is co-prime with φ(n)
  • Gear ratio calculations: finding the smallest gear tooth count for a given ratio
  • Tile pattern design: determining the smallest repeating unit for rectangular tiles

Steps:

  1. Enter two positive integers a and b.
  2. Apply integer division: a = q×b + r.
  3. Replace a with b and b with r. Repeat until r = 0.
  4. The last non-zero remainder is the GCD.
  5. Compute LCM = |a × b| / GCD using the fundamental identity.
  6. Use Multiple Numbers mode for three or more numbers.

Formula

Euclidean Algorithm: GCD(a, b) = GCD(b, a mod b) until b = 0 LCM from GCD: LCM(a, b) = |a × b| / GCD(a, b) For multiple numbers: GCD(a, b, c) = GCD(GCD(a, b), c) LCM(a, b, c) = LCM(LCM(a, b), c)

Use Cases

  • Simplifying fractions: reduce a/b by dividing both by GCD(a, b)
  • Adding fractions with different denominators: find LCM of denominators
  • Scheduling: finding when two recurring events will next coincide
  • RSA key generation: checking that exponent e is co-prime with φ(n)
  • Gear ratio problems in mechanical engineering
  • Tile pattern design: finding the smallest repeating unit

Key Benefits

  • Compute GCD and LCM instantly for two or more numbers using the Euclidean algorithm
  • See the complete step-by-step division process so you can learn and verify the algorithm
  • Automatically determine whether two numbers are co-prime (GCD = 1)
  • Simplify fractions by dividing numerator and denominator by their GCD
  • Handle large numbers efficiently — the algorithm works even for numbers with dozens of digits
  • Support for multiple numbers mode: compute GCD/LCM for lists of 3 or more values

Pro Tips

  • Use the GCD-LCM relationship: LCM(a,b) = |a×b| / GCD(a,b) — this is faster than listing multiples
  • Two numbers are co-prime if and only if GCD = 1 — check this before modular arithmetic calculations
  • For simplifying fractions, always divide both numerator and denominator by GCD(num, den)
  • When scheduling, convert all time periods to the same unit before computing LCM
  • Remember that GCD(0, n) = n and LCM(0, n) = 0 — zero is divisible by everything
  • For very large numbers, the Euclidean algorithm is still efficient — no need for prime factorization

Common Mistakes to Avoid

  • Confusing GCD with LCM: GCD is the largest common DIVISOR, LCM is the smallest common MULTIPLE
  • Thinking LCM is just a×b: this is only true when GCD(a,b) = 1 (co-prime numbers)
  • Forgetting that GCD and LCM extend to more than two numbers: GCD(a,b,c) = GCD(GCD(a,b), c)
  • Assuming the Euclidean algorithm requires prime factorization — it does not, which is why it is so efficient
  • Using LCM for simplifying fractions when you should use GCD
  • Not checking for co-prime status before RSA key generation — e must be co-prime with φ(n)

Key Terms Explained

GCD: Largest integer dividing both numbers without remainder
LCM: Smallest positive integer divisible by both numbers
Co-prime: Two numbers with GCD = 1, sharing no common prime factors
Euclidean algorithm: Ancient algorithm computing GCD by repeated division
Modulo operation: a mod b is the remainder when a is divided by b
Divisibility: a divides b if b/a has no remainder

Related Concepts

  • Prime Factorization: Break numbers into prime factors — the foundation for understanding GCD and LCM.
  • Fraction Calculator: Simplify, add, and subtract fractions using GCD for reduction.
  • Logarithm Calculator: Explore the logarithmic complexity of the Euclidean algorithm.
  • Percentage Calculator: Convert GCD/LCM results to percentages for ratio analysis.
  • Modular Arithmetic: Work with co-prime moduli in RSA cryptography and modular equations.

Example

Find GCD(48, 18): 48 = 2×18 + 12 → 18 = 1×12 + 6 → 12 = 2×6 + 0. GCD = 6. LCM = |48×18|/6 = 864/6 = 144. Check: 144/48 = 3 ✓, 144/18 = 8 ✓.

Interpreting Your Results

The GCD result tells you the largest number that divides both inputs evenly. If GCD = 1, the numbers are co-prime — they share no common factors beyond 1. The LCM result is the smallest number both inputs divide into evenly. A large GCD relative to the inputs means the numbers share many factors (e.g., GCD(12, 18) = 6). A GCD of 1 means the numbers are co-prime and LCM = a×b. The product identity GCD × LCM = |a×b| lets you verify: multiply your GCD and LCM results and confirm they equal the product of the original numbers.

Frequently Asked Questions

What is GCD and how is it calculated?
GCD (Greatest Common Divisor) is the largest positive integer that divides both a and b without remainder. The Euclidean algorithm computes it efficiently: repeatedly replace (a, b) with (b, a mod b) until b = 0. The last non-zero value is the GCD.
What is LCM and what is it used for?
LCM (Least Common Multiple) is the smallest positive integer divisible by both a and b. It is essential for adding fractions with different denominators, scheduling problems, gear ratios, and music theory (finding common rhythmic cycles).
What is the relationship between GCD and LCM?
GCD(a, b) × LCM(a, b) = |a × b|. Once you know the GCD, the LCM is simply |a × b| / GCD(a, b). This identity is more efficient than listing multiples and forms the basis for most GCD/LCM computations.
What does co-prime mean?
Two numbers are co-prime (relatively prime) if their GCD is 1 — they share no common prime factors. Co-primality is fundamental in modular arithmetic, RSA cryptography, and the Chinese Remainder Theorem. For example, 8 and 15 are co-prime because their only common divisor is 1.
What is the Euclidean algorithm?
The Euclidean algorithm, described by Euclid around 300 BC, computes the GCD by repeated division. For GCD(a, b): divide a by b to get remainder r, then replace a with b and b with r. Repeat until r = 0. The last non-zero remainder is the GCD. It runs in O(log(min(a,b))) steps.
How do I add fractions with different denominators?
Find the LCM of the denominators, convert each fraction to the common denominator, then add the numerators. For example, 1/3 + 1/4: LCM(3,4) = 12, so 4/12 + 3/12 = 7/12. This calculator computes the LCM for you.
What are the Euclidean algorithm steps for GCD(48, 18)?
Step 1: 48 = 2×18 + 12. Step 2: 18 = 1×12 + 6. Step 3: 12 = 2×6 + 0. The last non-zero remainder is 6, so GCD(48, 18) = 6. Then LCM = |48×18|/6 = 864/6 = 144.
How is GCD used in cryptography?
In RSA encryption, you need to choose an exponent e that is co-prime with φ(n), meaning GCD(e, φ(n)) = 1. This ensures the encryption function is invertible. The Euclidean algorithm is also used to compute modular inverses needed for key generation.
Can GCD be computed for more than two numbers?
Yes. GCD(a, b, c) = GCD(GCD(a, b), c). Compute the GCD of the first two numbers, then compute the GCD of that result with the third number. Our calculator supports lists of multiple numbers using this approach.
What is the time complexity of the Euclidean algorithm?
The Euclidean algorithm runs in O(log(min(a,b))) steps. For 64-bit numbers (up to ~18 quintillion), this means at most about 90 division steps. It is one of the most efficient classical algorithms ever discovered.
How is LCM used in real-world scheduling?
If event A occurs every 12 hours and event B occurs every 18 hours, they will next coincide after LCM(12, 18) = 36 hours. LCM is used for scheduling rotations, finding common cycles, and determining when periodic events align.

Discover More Tools

Fresh picks from across our tool library.