Mathematics RU

Practice · Chapter 4

GCD, LCM and the Euclidean algorithm

The greatest common divisor and the least common multiple, by factoring and by the Euclidean algorithm, and at the top level Bézout equations ax + by = c in integers.

How to solve it

The gcd is the largest number that divides both numbers; the lcm is the smallest number both divide. For small numbers both can be read from the prime factorizations; for large ones the Euclidean algorithm is faster: it divides with remainders without factoring anything.

Step by step

  1. By factoring: the gcd takes the common primes in the smallest powers, the lcm takes all primes in the largest powers.
  2. The Euclidean algorithm: divide the larger number by the smaller with a remainder, then the divisor by the remainder, and so on until the remainder is zero. The last non-zero remainder is the gcd.
  3. Get the lcm from the gcd: $\operatorname{lcm}(a, b) = \frac{a \cdot b}{\gcd(a, b)}$.
  4. The equation $ax + by = c$ is solvable only if $c$ is divisible by $\gcd(a, b)$. Run the Euclidean algorithm backwards to write the gcd through $a$ and $b$, then multiply by $\frac{c}{\gcd}$.
The larger number. The smaller number. The remainder of $a$ divided by $b$: the common divisors of the pair stay the same while the numbers get smaller. Example: $703 = 2 \cdot 247 + 209$, $247 = 1 \cdot 209 + 38$, $209 = 5 \cdot 38 + 19$, $38 = 2 \cdot 19 + 0$. The gcd is $19$.

Common mistakes

  • Taking the largest powers for the gcd and the smallest for the lcm. It is the other way round: the gcd cannot exceed the smaller number.
  • Answering with the zero remainder or the last quotient. The answer is the last non-zero remainder.
  • Not checking divisibility in a Bézout equation: $6x + 9y = 7$ has no integer solutions, because $7$ is not divisible by $3$.
  • Thinking a Bézout equation has one solution. There are infinitely many: add $\frac{b}{d}t$ to $x$ and subtract $\frac{a}{d}t$ from $y$.

Example