8.2 GCD, Euclid’s Algorithm, and Bézout’s Identity
Section 8.1 described every positive integer through its prime factors. If two numbers are already factored, their shared primes reveal their common divisors. But factorization is often much more work than we need.
This section develops a recursive alternative: repeatedly replace a pair by a smaller remainder pair while preserving all common divisors.
Common divisors and the greatest common divisor
Let and be integers, not both zero. An integer is a common divisor of and if
The greatest common divisor, written
is the greatest positive integer dividing both numbers.
For example, the positive divisors of are
while the positive divisors of are
Their positive common divisors are , so
The order does not matter:
For ,
because every divisor of divides , and the greatest positive divisor of is .
Reading a gcd from prime exponents
Suppose
and
A common divisor can use only primes present in both numbers, and for each shared prime it can use no more than the smaller exponent. Therefore
This method is conceptually useful, but it first requires both factorizations. Euclid's algorithm avoids that requirement.
The division algorithm produces a quotient and remainder
Let and let be a positive integer. The division algorithm states that there are unique integers and such that
Here:
- is the quotient;
- is the remainder;
- the inequality selects one unique remainder.
For example,
Thus dividing by gives quotient and remainder .
We write the remainder as
The expression “mod” here is a remainder operation. Section 8.3 will use the same idea to define congruence classes.
The key invariant of Euclid’s algorithm
If
then
Why are the common divisors unchanged?
First, suppose divides both and . Because
the integer-linear-combination rule from Section 8.1 gives . Thus every common divisor of is also a common divisor of .
Conversely, suppose divides both and . Since
we obtain . Thus every common divisor of is also a common divisor of .
The two pairs have exactly the same common divisors, so their greatest positive common divisor is the same.
This equality is an invariant: the pair of numbers changes, but its gcd does not.
Euclid’s algorithm step by step
To compute for positive integers :
1. divide by to obtain ;
2. replace the pair by ;
3. repeat until the remainder is ;
4. return the last nonzero remainder.
Example:
The corresponding invariant chain is
Therefore
Why the algorithm terminates
Every nonzero remainder satisfies
So the second component of the pair forms a strictly decreasing sequence of nonnegative integers. It cannot decrease forever. Eventually a remainder must be .
This is precisely the well-founded recursive reasoning from Chapter 7.
The algorithm can be written recursively as
The first line is the base case. The second line is the reducing recursive step.
Send two integer streams through a remainder waterfall. Each gate forms quotient-sized groups, pours the remainder into the next channel, and carries an invariant set of common-divisor tokens. Step manually or animate until the final nonzero channel reveals the gcd.
Bézout’s identity turns the gcd into a combination
For integers , not both zero, Bézout’s identity states that there exist integers such that
The numbers and are called Bézout coefficients. They are not usually unique.
Euclid's algorithm finds the gcd. The extended Euclidean algorithm also recovers coefficients by reversing the remainder equations.
Back-substitution example
The forward Euclidean equations were
and
Solve the second equation for the last nonzero remainder:
Now solve the first equation for :
Substitute this expression for :
Thus one pair of Bézout coefficients is
and we can check
Coefficient vectors preserve the original inputs
Another viewpoint tracks every remainder as a combination of the original pair.
Represent
by coefficient vector , and represent
by .
When a remainder is formed by
its coefficient vector is obtained by the same subtraction:
For the example:
and
The final vector gives the Bézout coefficients directly.
Which linear combinations are possible?
Because the gcd divides both and , it divides every integer combination . Bézout's identity also shows that the gcd itself is such a combination.
Therefore the equation
has integer solutions exactly when
For example,
has integer solutions because . Multiplying the Bézout identity by gives one solution:
But has no integer solution because .
Reverse an Euclidean trace through a coefficient-vector switchyard. At every junction, choose the quotient-weighted subtraction that rebuilds the previous remainder; incorrect substitutions visibly break the final identity, while a correct route produces checkable Bézout coefficients.
Section bridge
Bézout coefficients do more than solve linear equations. When , a coefficient in becomes a multiplicative inverse of modulo . Section 8.3 develops that modular viewpoint and then combines several remainder conditions with the Chinese Remainder Theorem.