GCD & LCM Calculator
Compute Greatest Common Divisor (GCD/GCF/HCF) and Least Common Multiple (LCM) for up to 15 integers with exact Euclidean division tables and prime exponent charts.
Step-by-Step Euclidean Algorithm Division Table
The Euclidean algorithm finds the GCD by repeatedly applying division with remainder: Dividend = Quotient × Divisor + Remainder until the remainder reaches exactly 0.
Prime Factorization Trees & Exponent Chart
The GCD is constructed by taking every shared prime raised to its minimum exponent across all numbers. The LCM is constructed by taking every prime raised to its maximum exponent across all numbers.
| Prime Factor (p) | Minimum Exponent (min e) | GCD Contribution (pmin) | Maximum Exponent (max e) | LCM Contribution (pmax) |
|---|---|---|---|---|
| 2 | 2 | Math.pow(2, 2) = 4 | 4 | Math.pow(2, 4) = 16 |
| 3 | 1 | Math.pow(3, 1) = 3 | 2 | Math.pow(3, 2) = 9 |
How is this calculated? (View worked mathematical solution)
The Euclidean algorithm evaluates pairwise greatest common divisors without needing prime factorization, while the reduction identity computes exact least common multiples:
Methodology & Mathematical Context
Euclidean Algorithm Efficiency: Discovered around 300 BC by Euclid (Elements, Book VII), the division algorithm computes GCD in logarithmic time proportional to the number of digits (O(log(min(a,b))) steps), making it vastly faster than prime tree decomposition.
Associative Multi-Integer Folding: Because integer ring divisibility is associative over the set of integers Z, lists of three or more integers are evaluated sequentially: GCD(a, b, c) = GCD(GCD(a, b), c).
Zero Divisibility Rule: Since 0 = k × 0 for any integer k, every non-zero integer a divides zero. Therefore, GCD(a, 0) = |a|, while LCM(a, 0) = 0 per NIST DLMF Chapter 27.
About the GCD & LCM Calculator
The Greatest Common Divisor (GCD) — also referred to as Greatest Common Factor (GCF) or Highest Common Factor (HCF) — and the Least Common Multiple (LCM) are foundational pillars of integer number theory and arithmetic. Whether simplifying complex fractions to lowest terms, synchronizing periodic cycles, or finding common grid dimensions, this instrument computes exact GCD and LCM values for up to 15 numbers simultaneously while revealing the underlying step-by-step Euclidean algorithm divisions and prime factorization frequency trees.
Mathematical Formula & Logic
Step-by-Step Example
Worked Examples: 1. Example 1 (Euclidean Algorithm for Two Numbers: 24 and 36): Divide 36 by 24 to get 1 remainder 12 (36 = 1×24 + 12). Next, divide 24 by 12 to get 2 remainder 0 (24 = 2×12 + 0). Since the remainder is now 0, the last non-zero remainder is 12, so GCD(24, 36) = 12. The LCM is evaluated as |24 × 36| / 12 = 864 / 12 = 72. 2. Example 2 (Three Numbers: 12, 18, and 24): Fold pairwise from left to right. First compute GCD(12, 18) = 6, then GCD(6, 24) = 6, yielding total GCD = 6. For LCM, compute LCM(12, 18) = (12×18)/6 = 36, then LCM(36, 24) = (36×24)/GCD(36, 24) = 864 / 12 = 72. 3. Example 3 (Coprime Numbers: 15 and 28): Applying the Euclidean algorithm: 28 = 1×15 + 13; 15 = 1×13 + 2; 13 = 6×2 + 1; 2 = 2×1 + 0. Since the last non-zero remainder is 1, GCD(15, 28) = 1 (coprime). Therefore, LCM(15, 28) = (15 × 28) / 1 = 420.
Reference Data & Values
| rule name | formula | applicability |
|---|---|---|
| Euclidean Algorithm for Pairwise GCD | GCD(a, b) = GCD(b, a mod b) repeatedly until the remainder equals 0, at which point the last non-zero divisor is the GCD. | Applies to any pair of integers where at least one operand is non-zero. |
| Pairwise LCM via Product-GCD Reduction | LCM(a, b) = |a * b| / GCD(a, b) | Applies to non-zero integers a and b. If either a=0 or b=0, LCM(a,b) = 0 by convention. |
| Associative Multi-Integer Generalization | For N integers, compute GCD and LCM sequentially by folding across the sequence: GCD(a, b, c) = GCD(GCD(a, b), c) and LCM(a, b, c) = LCM(LCM(a, b), c). | Applies to any finite set of N >= 3 integers. |