The gcd is the smallest positive combination
{ax + by} over all integers x, y is exactly the set of multiples of gcd(a,b), so the gcd is its smallest positive member.
gcd(a,b) = ax + by for some integers x, y, found by running Euclid's algorithm backwards. When gcd(a,m) = 1 the coefficient of a is its inverse modulo m.
Core ideas
Bézout upgrades the gcd from a number to an identity, and the identity is what produces inverses and proves unique factorisation.
{ax + by} over all integers x, y is exactly the set of multiples of gcd(a,b), so the gcd is its smallest positive member.
Each division a = qb + r gives r = a − qb; substituting upward expresses the gcd in terms of the original inputs.
ax + my = 1 reduces mod m to ax ≡ 1, so x is a⁻¹. This is where every modular inverse in this course comes from.
The material
The identity, the extended algorithm, and the two theorems it unlocks.
For integers a, b not both zero there are integers x, y with ax + by = gcd(a,b). Moreover gcd(a,b) is the smallest positive integer expressible in that form.
Let S = {ax + by : x, y ∈ ℤ, ax + by > 0}, which is nonempty (it contains |a|). By well-ordering (“The Well-Ordering Principle” in Induction and Recursion) it has a least element d = ax₀ + by₀.
Divide: a = qd + r with 0 ≤ r < d. Then r = a − qd = a(1 − qx₀) + b(−qy₀), which is of the required form. Since 0 ≤ r < d and d is the smallest positive such value, r = 0, so d | a. Similarly d | b, so d is a common divisor.
Any common divisor c of a and b divides ax₀ + by₀ = d, so c ≤ d. Hence d = gcd(a,b).
□
The proof establishes existence; the algorithm produces the coefficients. Run Euclid forward recording the quotients, then substitute backwards.
The iterative form maintains the coefficients as it goes and avoids the back-substitution entirely: alongside each remainder r it keeps s and t with r = as + bt, updating all three by the same "subtract q times the row above" step. It is what the lab runs, row by row with the identity checked on every line, and what every implementation uses.
a has an inverse modulo m — an x with ax ≡ 1 (mod m) — if and only if gcd(a, m) = 1. The inverse is then unique modulo m.
If gcd(a,m) = 1, Bézout gives ax + my = 1, and reducing modulo m leaves ax ≡ 1.
Conversely if ax ≡ 1 (mod m) then ax − 1 = my for some y, so ax − my = 1, and any common divisor of a and m divides 1.
For uniqueness: if ax ≡ ax' ≡ 1 then x ≡ x(ax') = (xa)x' ≡ x'.
□
This is the theorem RSA runs on. The private exponent d is the inverse of the public exponent e modulo φ(n), and it is computed by exactly this algorithm.
If a prime p divides ab, then p | a or p | b.
Suppose p ∤ a. Since p is prime, gcd(p, a) = 1, so Bézout gives px + ay = 1. Multiplying by b: pbx + aby = b.
p divides pbx, and p divides ab hence aby. So p divides their sum, which is b.
□
Euclid's lemma is what makes prime factorisation unique, so “Primes and Unique Factorisation”'s fundamental theorem rests on Bézout, which rests on well-ordering. The chain of dependency is worth noticing: the most familiar fact in the course has the deepest justification.
Interactive
Algorithms with their traces
Method
Forward for the gcd, backward for the coefficients.
Each line a = qb + r will be rearranged as r = a − qb.
That is the gcd. Express it using the line that produced it.
Replace each remainder by its expression in earlier terms, collecting coefficients as you go.
Compute ax + by and check it equals the gcd. A sign error here is easy and the check is one multiplication.
The computation RSA needs, on the standard textbook key.
The negative coefficient is normal and is corrected by adding the modulus. This calculation is the entire key-generation step of RSA: everything else is multiplication and exponentiation.
Find the inverse of 7 modulo 26 by the extended algorithm and verify it. That is the decryption key for the affine cipher in “Classical Ciphers”, and the same computation scaled up is RSA's private exponent.
Something to change about this lesson? Write it down, tick it off when it is handled, and export the list when you want to act on it. Kept in this browser only: nothing is sent anywhere, and nobody is notified.
No recommendations yet for this lesson.