About the gcd and lcm calculator
The greatest common divisor of two integers is the largest integer dividing both of them. The calculator uses the Euclidean algorithm, which repeatedly replaces the larger number by its remainder on division by the smaller until the remainder is zero. The last non-zero remainder is the greatest common divisor, and the method finishes in a handful of steps even for very large inputs.
The least common multiple is the smallest positive integer both numbers divide. It follows from the greatest common divisor: the product of the two numbers divided by their greatest common divisor. Working through the divisor first is what keeps the arithmetic small.
Two integers are coprime, or relatively prime, when their greatest common divisor is 1. That is the condition for a modular inverse to exist, so this calculator and the modular arithmetic one answer two halves of the same question. Values are handled as arbitrary precision integers, so inputs longer than a machine word are exact rather than rounded.
Worked example
Worked example
Inputa = 48, b = 18
Resultgcd(48, 18) = 6, lcm(48, 18) = 144
Euclid: 48 = 2 x 18 + 12, 18 = 1 x 12 + 6, 12 = 2 x 6 + 0. The lcm is 48 x 18 / 6 = 144.