Find the Greatest Common Divisor and Least Common Multiple for 2 or more comma-separated numbers. Uses the Euclidean algorithm and BigInt for large integer accuracy.
Enter 2 or more integers separated by commas or spaces
GCD
6
Greatest Common Divisor
LCM
72
Least Common Multiple
GCD(12, 18, 24) = 6 LCM(12, 18, 24) = 72
The Greatest Common Divisor (GCD) - also termed the Highest Common Factor (HCF) - is the largest positive integer that divides two or more integers without a remainder. The Least Common Multiple (LCM) is the smallest positive integer divisible by all given integers. These fundamental operations are applied in fraction reduction, clock synchronization, modular arithmetic, and cryptography.
The Euclidean algorithm, documented by Euclid around 300 BC, computes the GCD of two numbers efficiently without factoring them into primes:
$$\gcd(a, b) = \gcd(b, a % b)$$
The process repeats until the remainder becomes zero; the last non-zero divisor is the GCD.
| Pair $(a, b)$ | Calculation Steps | $\gcd(a, b)$ | $\text{lcm}(a, b)$ |
|---|---|---|---|
| $(48, 18)$ | $48 = 18 \times 2 + 12 \rightarrow 18 = 12 \times 1 + 6 \rightarrow 12 = 6 \times 2 + 0$ | $6$ | $144$ |
| $(105, 45)$ | $105 = 45 \times 2 + 15 \rightarrow 45 = 15 \times 3 + 0$ | $15$ | $315$ |
| $(17, 19)$ | Prime numbers (coprime) | $1$ | $323$ |
For any two positive integers $a$ and $b$, the product of their GCD and LCM equals the product of the numbers:
$$\gcd(a, b) \times \text{lcm}(a, b) = a \times b$$ $$\text{lcm}(a, b) = \frac{|a \times b|}{\gcd(a, b)}$$
JavaScript
function gcd(a, b) {
let x = Math.abs(a);
let y = Math.abs(b);
while (y !== 0) {
const temp = y;
y = x % y;
x = temp;
}
return x;
}
function lcm(a, b) {
if (a === 0 || b === 0) return 0;
return Math.abs(a * b) / gcd(a, b);
}
Python (math module)
import math
a, b = 48, 18
print("GCD:", math.gcd(a, b)) # Output: 6
print("LCM:", math.lcm(a, b)) # Output: 144
This website and utility are provided for general informational, calculation, and educational purposes only. Always verify critical computation outputs prior to professional deployment or financial use. See our Terms of Service and Privacy Policy for full governance details.