1 Greatest Common Divisor and Least Common Multiple
For integers a,b, not both zero, the greatest common divisor of a and b is the largest positive integer d satisfying d∣a and d∣b. We write d=gcd(a,b). When gcd(a,b)=1, we say a and b are coprime.
For positive integers a,b, the least common multiple is the smallest positive integer m satisfying a∣m and b∣m. We write m=lcm(a,b).
For positive integers a,b, we have gcd(a,b)⋅lcm(a,b)=ab.
Set d=gcd(a,b) and write a=da′, b=db′ with gcd(a′,b′)=1. It suffices to show that lcm(a,b)=da′b′. Clearly a∣da′b′ and b∣da′b′. Now let m be any positive integer with a∣m and b∣m. Write m=da′k. Then db′∣da′k, so b′∣a′k. Since gcd(a′,b′)=1, we obtain b′∣k, and therefore da′b′∣m. Hence lcm(a,b)=da′b′=ab/d. □
2 The Euclidean Algorithm
For positive integers a≥b, write a=bq+r with 0≤r<b by the division algorithm. Then gcd(a,b)=gcd(b,r).
If d∣a and d∣b, then d∣(a−bq)=d∣r. Conversely, if d∣b and d∣r, then d∣(bq+r)=d∣a. Thus the sets of common divisors of {a,b} and {b,r} coincide, and in particular their maxima agree. □
The Euclidean algorithm terminates in O(logmin(a,b)) iterations.
In the step a=bq+r, we have r<b; in fact, one can show r≤a/2. If b≤a/2, then r<b≤a/2. If b>a/2, then q=1 and r=a−b<a/2. Therefore the remainder is at least halved every two iterations, giving O(logmin(a,b)) total steps. □
3 Bézout's Identity
For integers a,b, not both zero, there exist integers x,y such that ax+by=gcd(a,b).
Consider the set S={ax+by∣x,y∈Z,ax+by>0}. Since S=∅ (for instance, a2+b2>0 belongs to S for a suitable combination), the well-ordering principle furnishes a least element d=ax0+by0. We claim d∣a. By the division algorithm, a=dq+r with 0≤r<d. Then r=a−dq=a(1−qx0)+b(−qy0) lies in S∪{0}. Since r<d and d is the least element of S, we must have r=0, so d∣a. Similarly d∣b, so d is a common divisor. Conversely, if c∣a and c∣b, then c∣d, which forces d=gcd(a,b). □
4 The Extended Euclidean Algorithm
The extended Euclidean algorithm computes, alongside gcd(a,b), the Béx,y satisfying ax+by=gcd(a,b).
Compute gcd(252,198): 252=1⋅198+54, 198=3⋅54+36, 54=1⋅36+18, 36=2⋅18+0. Hence gcd(252,198)=18. Back-substituting: 18=54−1⋅36=54−1⋅(198−3⋅54)=4⋅54−198=4(252−198)−198=4⋅252−5⋅198.
5 Solving Linear Congruences
The congruence ax≡b(modn) has a solution if and only if gcd(a,n)∣b. When solutions exist, there are exactly d=gcd(a,n) solutions modulo n.
The congruence ax≡b(modn) is equivalent to the existence of integers x,y with ax+ny=b. By Bé{ax+ny∣x,y∈Z}=gcd(a,n)Z, so b lies in this set precisely when gcd(a,n)∣b. When d=gcd(a,n)∣b, the reduced congruence (a/d)x≡b/d(modn/d) has gcd(a/d,n/d)=1 and therefore a unique solution x0. The solutions of the original congruence are x≡x0+kn/d(modn) for k=0,1,…,d−1, giving d solutions in all. □