Greatest Common Divisor
Definition
For integers a and b (not both zero), the greatest common divisor gcd(a,b) is the largest positive integer d such that d∣a and d∣b.
By convention, gcd(0,0)=0.
Examples
- gcd(12,18)=6
- gcd(17,5)=1
- gcd(100,0)=100
Coprimality
We say a and b are coprime or relatively prime if gcd(a,b)=1.
Properties of GCD
Symmetry
gcd(a,b)=gcd(b,a)
Absolute Value
gcd(a,b)=gcd(∣a∣,∣b∣)
If a∣b
If a=0 and a∣b, then gcd(a,b)=∣a∣.
Adding Multiples
For any integers k,ℓ:
gcd(a,b)=gcd(a−kb,b)
This is the key insight behind Euclid’s algorithm.
Euclid’s Algorithm
The Key Lemma
gcd(a,b)=gcd(b,amodb)
Proof: Let a=bq+r with 0≤r<b.
Any common divisor of a and b divides r=a−bq.
Any common divisor of b and r divides a=bq+r.
Thus {d:d∣a∧d∣b}={d:d∣b∧d∣r}.
Taking the maximum, gcd(a,b)=gcd(b,r)=gcd(b,amodb).
The Algorithm
Euclid’s algorithm computes gcd(a,b) recursively:
function gcd(a, b):
if b = 0:
return a
else:
return gcd(b, a mod b)
Termination
The second argument strictly decreases at each step: amodb<b.
Since b≥0 and the non-negative integers are well-ordered, the algorithm terminates.
Example
Compute gcd(48,18):
| Step | a | b | amodb |
|---|
| 1 | 48 | 18 | 12 |
| 2 | 18 | 12 | 6 |
| 3 | 12 | 6 | 0 |
| 4 | 6 | 0 | — |
gcd(48,18)=6.
Bézout’s Identity
Statement
Theorem (Bézout’s Identity): For integers a and b (not both zero), there exist integers x and y such that:
ax+by=gcd(a,b)
Extended Euclidean Algorithm
We compute x and y alongside the GCD by tracking linear combinations.
Example: Find integers x,y with 48x+18y=gcd(48,18)=6.
Working through Euclid’s algorithm:
- 48=2⋅18+12
- 18=1⋅12+6
- 12=2⋅6+0
Back-substituting:
- 6=18−1⋅12
- 6=18−1⋅(48−2⋅18)=3⋅18−1⋅48
So x=−1 and y=3 verify 48⋅(−1)+18⋅3=−48+54=6.
Euclid’s Lemma
Statement
Lemma (Euclid’s Lemma): If p is prime and p∣ab, then p∣a or p∣b.
Proof
Suppose p∤a. Since p is prime, gcd(p,a)=1.
By Bézout’s Identity, there exist x,y with px+ay=1.
Multiply by b: pxb+aby=b.
Since p∣ab, we have p∣aby. Clearly p∣pxb.
Thus p∣(pxb+aby)=b.
Multiplicativity of GCD
Statement
If gcd(b,c)=1, then:
gcd(a,bc)=gcd(a,b)⋅gcd(a,c)
Proof Sketch
Let d1=gcd(a,b) and d2=gcd(a,c).
Since gcd(b,c)=1 and d1∣b, d2∣c, we have gcd(d1,d2)=1.
Both d1 and d2 divide a, so d1d2 divides a.
Both d1 and d2 divide bc (since d1∣b and d2∣c), so d1d2 divides bc.
Thus d1d2∣gcd(a,bc).
For the reverse, use Bézout’s identity with the coprimality assumptions.
Summary
- gcd(a,b) is the largest common divisor, defined for a,b not both zero
- Key lemma: gcd(a,b)=gcd(b,amodb)
- Euclid’s algorithm terminates by well-foundedness
- Bézout’s Identity: ax+by=gcd(a,b) for some x,y
- Euclid’s Lemma: if prime p∣ab, then p∣a or p∣b