NUMBER THEORY · CLASSICAL CONSTRUCTIONS · INTERMEDIATE

Euclidean Algorithm Theorem

Repeated division with remainder finds the greatest common divisor of two integers without factoring either number. The key theorem is simple: replacing a pair by the smaller number and the remainder preserves every common divisor, and the remainders eventually reach zero.

THEOREM STATEMENT

The gcd is unchanged by division with remainder

For integers a and b with b ≠ 0, write a = qb + r, where q is an integer and 0 ≤ r < |b|. Then the common divisors of a and b are exactly the common divisors of b and r.

gcd⁡(a,b)=gcd⁡(b,r)when a=qb+r\gcd(a,b)=\gcd(b,r)\qquad\text{when }a=qb+r

Applying this identity repeatedly ends at a zero remainder. The last nonzero remainder is the greatest common divisor. For signed inputs, the algorithm is applied to absolute values; by convention gcd(a, 0) = |a|.

Repeated division reduces a pair of integers while preserving the gcdA sequence shows 252 and 105 becoming 105 and 42, then 42 and 21, then 21 and zero. The final nonzero remainder 21 is the greatest common divisor.Each division keeps the same common divisors(252, 105)(105, 42)(42, 21)(21, 0)gcd = 21gcd = 21gcd = 21stop252 = 2·105 + 42105 = 2·42 + 2142 = 2·21 + 0The last nonzero remainder is gcd(252, 105) = 21
Each replacement preserves the gcd. The decreasing remainders force the process to stop, and the final nonzero remainder is 21.

Why the gcd stays the same

Suppose d divides both a and b. Since r = a − qb, d also divides r: a divisor of two integers divides any integer linear combination of them. Thus every common divisor of a and b is a common divisor of b and r.

For the reverse direction, suppose d divides b and r. From a = qb + r, d divides a as well. The two pairs therefore have exactly the same common divisors, including their greatest positive common divisor.

d∣a and d∣b  ⟺  d∣b and d∣(a−qb)=rd\mid a\text{ and }d\mid b\iff d\mid b\text{ and }d\mid(a-qb)=r

This argument proves the invariant at every step. The algorithm is not guessing a smaller answer: it transforms the inputs into a simpler pair with an identical set of common divisors.

How the Euclidean algorithm works

  1. 1
    Order the positive inputs.

    For nonzero integers, work with their absolute values. If necessary, swap them so the first is at least the second.

  2. 2
    Divide and record the remainder.

    Write the larger value as quotient times smaller value plus a remainder from 0 up to, but not including, the divisor.

    a0=q0a1+r1,qquad0≤r1<a1a_0=q_0a_1+r_1,qquad 0\le r_1<a_1
  3. 3
    Repeat with the divisor and remainder.

    The previous divisor becomes the new larger number, and the remainder becomes the new divisor.

    a1=q1r1+r2,qquada2=q2r2+r3,quad…a_1=q_1r_1+r_2,qquad a_2=q_2r_2+r_3,quad\ldots
  4. 4
    Stop at remainder zero.

    The last nonzero remainder divides the previous remainder and, by the invariant, is the gcd of the original inputs.

The algorithm terminates because each nonzero remainder is a smaller nonnegative integer than the divisor that produced it. A strictly decreasing sequence of nonnegative integers cannot continue forever.

Worked example: gcd of 252 and 105

Use repeated division. Each line replaces the pair by the divisor and remainder, while preserving the greatest common divisor.

  1. 1
    Divide 252 by 105.

    The quotient is 2 and the remainder is 42.

    252=2(105)+42⇒gcd⁡(252,105)=gcd⁡(105,42)252=2(105)+42\quad\Rightarrow\quad\gcd(252,105)=\gcd(105,42)
  2. 2
    Divide 105 by 42.

    The quotient is 2 and the remainder is 21.

    105=2(42)+21⇒gcd⁡(105,42)=gcd⁡(42,21)105=2(42)+21\quad\Rightarrow\quad\gcd(105,42)=\gcd(42,21)
  3. 3
    Divide 42 by 21.

    The remainder is zero, so the last nonzero remainder, 21, is the answer.

    42=2(21)+0⇒gcd⁡(252,105)=2142=2(21)+0\quad\Rightarrow\quad\boxed{\gcd(252,105)=21}

A quick check confirms the result: 252 = 12·21 and 105 = 5·21. No larger integer can divide both, as the remainder chain would then also have to be divisible by it, including 21.

Back-substitution and Bézout’s identity

The division equations can be rearranged from the last nonzero remainder backward. This expresses the gcd as an integer linear combination of the original numbers.

21=105−2(42)=105−2(252−2⋅105)=5⋅105−2⋅25221=105-2(42)=105-2(252-2\cdot105)=5\cdot105-2\cdot252

Thus there exist integers x and y such that gcd(a, b) = ax + by. This is Bézout’s identity. The coefficients x = −2 and y = 5 work for 252 and 105. The extended Euclidean algorithm computes these coefficients while performing the same remainder steps.

Bézout coefficients are useful beyond finding a gcd. If gcd(a, m) = 1, the identity ax + my = 1 shows that x is a multiplicative inverse of a modulo m. This makes the extended algorithm central to modular arithmetic and elementary cryptography.

Classical geometry and commensurable lengths

Euclid presented the numerical algorithm in Book VII of the Elements. The corresponding geometric idea is the method of successive subtraction: repeatedly remove the largest whole copy of a shorter length from a longer one.

If two segment lengths are integer multiples of some common unit, they are commensurable. The algorithm finds a greatest common measure by reducing the pair. For example, lengths 252 and 105 units share a greatest integer measure of 21 units because both are exact multiples of 21.

For arbitrary real lengths, the geometric process may not terminate. If the ratio is irrational, successive remainders can continue indefinitely, as in the classical construction for the diagonal of a unit square. For integers, in contrast, the strictly decreasing remainder sequence guarantees termination.

Applications of the Euclidean algorithm

Simplify fractions

Divide numerator and denominator by their gcd to write a fraction in lowest terms.

252105=252÷21105÷21=125\frac{252}{105}=\frac{252\div21}{105\div21}=\frac{12}{5}

Find a least common multiple

Once the gcd is known, use the product identity for positive integers.

lcm⁡(a,b)=abgcd⁡(a,b)\operatorname{lcm}(a,b)=\frac{ab}{\gcd(a,b)}

Modular inverses

The extended form finds integers that solve ax ≡ 1 (mod m) when a and m are coprime.

Diophantine equations

Bézout’s identity helps decide whether ax + by = c has integer solutions.

The basic algorithm is efficient even for very large integers: after only a modest number of divisions, the remainders shrink rapidly. It avoids the potentially expensive task of factoring both inputs into primes.

Assumptions and common mistakes

  • Stopping at the zero remainder: the gcd is the last nonzero remainder, not zero.
  • Keeping the pair in the wrong order: divide the larger magnitude by the smaller one to get a remainder smaller than the divisor.
  • Confusing quotient and remainder: the quotient counts whole groups; the remainder is what is left.
  • Ignoring signs: gcd is conventionally nonnegative, so compute with absolute values.
  • Assuming gcd(0, 0) is defined: many contexts leave it undefined; standard algorithm statements exclude both inputs being zero.
  • Claiming real-length termination: integer termination follows from discrete decreasing remainders; arbitrary real lengths need not terminate.

Euclidean Algorithm Theorem FAQs

What does the Euclidean algorithm theorem say?

If a = qb + r, then gcd(a, b) = gcd(b, r). Repeated application finds the gcd as the last nonzero remainder.

Why does the algorithm always terminate for integers?

Each nonzero remainder is a smaller nonnegative integer than the previous divisor. This sequence must reach zero after finitely many steps.

What is the greatest common divisor of 0 and a?

For nonzero integer a, gcd(a, 0) = |a|. The pair (0, 0) is commonly left undefined because every integer divides zero.

How is the extended Euclidean algorithm different?

It also tracks coefficients x and y so that ax + by = gcd(a, b), giving Bézout’s identity and enabling modular inverse calculations.

How does the algorithm connect to geometry?

Euclid’s Book VII presents the integer process, while successive subtraction gives a geometric analogue for finding a common measure of commensurable lengths.