Math / GCD & LCM

GCD & LCM calculator

Calculate the greatest common divisor and least common multiple of two whole integers, including negative and zero values.

Both results are non-negative. By convention, GCD(0, 0) and LCM(0, 0) are both 0.

Your answer will appear here.

Formula: GCD uses the Euclidean algorithm. LCM is |a × b| ÷ GCD(a, b), with LCM equal to zero when either input is zero.

The basics

Divisors, multiples, and the Euclidean algorithm

The greatest common divisor is the largest number that divides both inputs evenly; the least common multiple is the smallest number both inputs divide into. The two are linked: GCD × LCM equals the product of the absolute values, which is how this tool derives the LCM once the GCD is known.

GCD is the same divisor used to reduce fractions and ratios, so the Fraction calculator and the Ratio Simplifier rely on it under the hood.

How the formula works

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

The Euclidean algorithm finds the GCD by repeated remainder division; the LCM follows from the product rule above.

Zero inputs

The LCM is zero when either input is zero, following the standard convention.

Negative numbers

Signs are ignored; the divisor and multiple are positive.

In practice

Worked examples

Input

−24, 18

Answer

GCD = 6; LCM = 72

Input

0, 9

Answer

GCD = 9; LCM = 0

Good to know

Frequently asked questions

Yes. The calculator uses absolute values, so both the GCD and LCM are always non-negative.

Keep going