Connect via MCP →

Enter Calculation

Enter two or more positive whole numbers, e.g. 12, 18, 24

Formula

Advertisement

Results

Greatest Common Divisor (G.C.D.)
6
also called GCF / HCF
Least Common Multiple (L.C.M.)
72
smallest common multiple
Numbers entered 3
Method Euclidean algorithm

What this calculator does

This tool finds two key number-theory quantities for any list of two or more whole numbers: the Greatest Common Divisor (G.C.D.) — also known as the Greatest Common Factor (GCF) or Highest Common Factor (HCF) — and the Least Common Multiple (L.C.M.). The GCD is the largest positive integer that divides every input exactly. The LCM is the smallest positive integer that every input divides into without a remainder. These appear everywhere from simplifying fractions and finding common denominators to scheduling, gear ratios and cryptography.

How to use it

Type two or more positive integers separated by commas or spaces, for example 12, 18, 24, and submit. Negative numbers are converted to their absolute value, and decimals are rounded to the nearest integer. The calculator returns both the GCD and the LCM at once. If any value is zero, the LCM is reported as 0, because zero has no positive multiple in common with other numbers.

The formula explained

For two numbers the GCD uses the Euclidean algorithm: replace the pair \((a, b)\) with \((b, a \bmod b)\) over and over until the second value becomes 0; the first value left is the GCD. The LCM is then derived as $$\operatorname{lcm}(a,b) = \frac{a}{\gcd} \times b,$$ an ordering chosen to limit overflow. For three or more numbers the result is built up pairwise: combine the running answer with the next number, then with the next, and so on.

$$\begin{gathered} \gcd(a_1,\dots,a_k), \qquad \operatorname{lcm}(a_1,\dots,a_k) = \frac{|a_i \cdot a_j|}{\gcd(a_i,a_j)} \\[1.5em] \text{where}\quad \left\{ \begin{aligned} a_1,\dots,a_k &= \text{Integers (abs. values)} \\ \gcd &= \text{computed via the Euclidean algorithm} \end{aligned} \right. \end{gathered}$$

Venn diagram with intersection labeled GCD and union labeled LCM of two numbers
Shared prime factors form the GCD; all factors together form the LCM.
Step chain showing the Euclidean algorithm replacing gcd(a,b) with gcd(b, a mod b)
The Euclidean algorithm repeatedly replaces the pair until the remainder reaches zero.

Worked example

Take 12, 18, 24. First \(\gcd(12, 18) = 6\), then \(\gcd(6, 24) = 6\), so the G.C.D. is 6. For the LCM: $$\operatorname{lcm}(12, 18) = \frac{12 \times 18}{6} = 36, \qquad \operatorname{lcm}(36, 24) = \frac{36 \times 24}{12} = 72,$$ so the L.C.M. is 72. Check: \(72 \div 12 = 6\), \(72 \div 18 = 4\), \(72 \div 24 = 3\), and 6 divides all three inputs.

FAQ

Is GCD the same as GCF or HCF? Yes — Greatest Common Divisor, Greatest Common Factor and Highest Common Factor are three names for the same number.

What if two numbers share no common factor? If the GCD is 1 the numbers are coprime, and their LCM is simply the product of the numbers.

Can I enter more than two numbers? Yes. Enter as many integers as you like; the GCD and LCM are computed across the whole list.

Last updated: