GCD & LCM Calculator
Enter two positive integers to find their greatest common divisor (GCD) and least common multiple (LCM).
Check the active inputs and the formula domain. Blank, malformed or out-of-range values clear every result.
Enter 2–50 positive integers, up to 100 digits each. The least common multiple may have up to 1200 digits. The first 80 Euclidean steps are shown; prime factorization supports values up to 10¹².
Approximate results show up to 12 significant digits. Decimal fields use a dot, up to 12 digits on each side, an exponent from −24 to 24 and absolute values up to 10¹². Rational intermediate numerators and denominators are limited to 512 bits. Integer and scientific-notation exceptions are specified below. g=gcd(a,b); lcm(a,b)=a/g·b; a,b ∈ ℕ; 1–100 digits.
How GCD and LCM are calculated
The greatest common divisor (GCD) of two numbers is the largest number that divides both evenly. This calculator finds it using the Euclidean algorithm, which repeatedly replaces the larger number with the remainder of dividing it by the smaller, until the remainder is zero.
The least common multiple (LCM) is the smallest number that's a multiple of both inputs, calculated as LCM = (a × b) / GCD(a, b) — once you know the GCD, the LCM follows directly from this relationship.
Frequently asked questions
What's the GCD of two numbers that share no common factors?
If two numbers have no common factors other than 1 (they're called coprime), their GCD is 1 — for example, GCD(8, 15) = 1.
What are GCD and LCM used for?
GCD is used to simplify fractions to lowest terms; LCM is used to find a common denominator when adding or subtracting fractions, and in scheduling problems involving repeating cycles.
How does the Euclidean algorithm work?
It repeatedly applies GCD(a, b) = GCD(b, a mod b) until b reaches 0 — at that point, a is the GCD. This converges very quickly, even for large numbers.
How we verified this calculator
The calculator is checked against 6 reference cases computed independently of its code. Last passed: .
| # | Inputs | Expected result |
|---|---|---|
| 1 |
a = 1
b = 999
|
GCD: 1
LCM: 999
|
| 2 |
a = 123
b = 123
|
GCD: 123
LCM: 123
|
| 3 |
Mode = List of numbers
Positive integers = 12,18;24
|
GCD: 6
LCM: 72
|
| 4 |
Mode = List of numbers
Positive integers = 1 1
|
GCD: 1
LCM: 1
|
| 5 |
Mode = List of numbers
Positive integers = 999983 999979
|
GCD: 1
LCM: 999962000357
|
| 6 |
Mode = List of numbers
Positive integers = 1000000000000 12
|
GCD: 4
LCM: 3000000000000
|