Skip to content
Calculated in the browser

GCD and LCM

Two integers. The sign does not matter: the absolute value is used.

How it is calculated

The GCD is found by Euclid’s algorithm: the larger number is replaced by the remainder until that remainder is zero. The LCM is the product of the absolute values, divided by the GCD.

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

Where the numbers come from

  • First number
  • Second number

Example

12 and 18. GCD 6, LCM 36.

Questions

Can the numbers be fractional?

No. The school GCD is defined for integers.

What about zero?

GCD(0, 5) = 5. GCD(0, 0) is undefined.

For three numbers?

Find the GCD of the first two, then the GCD of that result and the third number. The LCM works the same way.