GCD determines which linear congruences are solvable, how many solutions they have, and when inverses exist modulo m. Includes Euler's totient and the Chinese Remainder Theorem.
A linear Diophantine equation ax+by=c and a linear congruence ax≡c(modb) are the same object, written differently.
In ax+by=c, you're asking: does there exist an integer x such that c−ax is a multiple of b? That's exactly ax≡c(modb).
So everything from the Diophantine theory translates directly. But the modular language opens new questions — particularly about inverses — that are worth developing on their own.
When is a invertible modulo m?
Question. When does ax≡1(modm) have a solution?
This is asking: when does a have a multiplicative inverse mod m?
Theorem. a has an inverse modulo m if and only if gcd(a,m)=1.
Proof. ax≡1(modm) means ax−1=my for some integer y, i.e., ax+m(−y)=1. By Bezout, this is solvable iff gcd(a,m)∣1, i.e., gcd(a,m)=1. ■
When gcd(a,m)=1, the Bezout coefficients give the inverse directly.
Example. Find 3−1(mod7).
From Bezout: 3(5)+7(−2)=1. So 3×5≡1(mod7). Thus 3−1≡5(mod7).
Solving ax≡b(modm)
Theorem. The congruence ax≡b(modm) has a solution if and only if d=gcd(a,m) divides b.
When solutions exist, there are exactly d solutions modulo m.
Method:
- Check d=gcd(a,m) divides b. If not, no solution.
- Divide through by d: dax≡db(moddm).
- Now gcd(a/d,m/d)=1, so a/d is invertible mod m/d. Find the inverse.
- One solution mod m/d. Lift to d solutions mod m by adding multiples of m/d.
Example. Solve 6x≡4(mod10).
d=gcd(6,10)=2 and 2∣4. ✓
Divide: 3x≡2(mod5).
Inverse of 3 mod 5: 3×2=6≡1(mod5), so 3−1≡2.
x≡2×2=4(mod5).
Lift to mod 10: x≡4 or x≡9(mod10). Two solutions, matching d=2.
Euler's Totient — how many invertibles?
The number of integers in {1,2,…,m} coprime to m is denoted ϕ(m), Euler's totient function.
These are exactly the integers with inverses mod m.
Formula. If m=p1a1p2a2⋯pkak, then:
ϕ(m)=m∏p∣m(1−p1)
Examples:
- ϕ(p)=p−1 for prime p (all of 1,…,p−1 are coprime to p).
- ϕ(pk)=pk−pk−1=pk−1(p−1).
- ϕ(1000)=1000×(1−21)(1−51)=400.
Euler's Theorem. If gcd(a,m)=1, then aϕ(m)≡1(modm).
Fermat's Little Theorem is the prime case: ap−1≡1(modp) for prime p∤a.
Chinese Remainder Theorem
When you have a system of congruences with different moduli, the Chinese Remainder Theorem (CRT) tells you when a simultaneous solution exists.
Theorem. The system:
x≡a1(modm1),x≡a2(modm2)
has a unique solution modulo m1m2 if and only if gcd(m1,m2)=1.
Why the GCD condition? The system requires x to be in two arithmetic progressions simultaneously. These progressions intersect iff their "step" relationship is compatible — which happens iff gcd(m1,m2)∣a1−a2.
When gcd(m1,m2)=1, this is always satisfied.
Construction. Let M=m1m2, M1=m2, M2=m1.
Find y1 such that M1y1≡1(modm1) (i.e., m2y1≡1(modm1)).
Find y2 such that M2y2≡1(modm2).
Then x=a1M1y1+a2M2y2(modM) is the unique solution.
Example. Solve: x≡2(mod3), x≡3(mod5).
gcd(3,5)=1. ✓ M=15, M1=5, M2=3.
5y1≡1(mod3): 5≡2(mod3), so 2y1≡1(mod3), y1=2.
3y2≡1(mod5): y2=2.
x=2×5×2+3×3×2=20+18=38≡8(mod15).
Check: 8=2×3+2 ✓, 8=1×5+3 ✓.
General CRT. For pairwise coprime m1,…,mk, the system has a unique solution modulo m1m2⋯mk. The pairwise coprime condition is essential — and it's a GCD condition.
Worked problems
Problem 1. Find x such that x≡1(mod2), x≡2(mod3), x≡3(mod5).
gcd of all pairs is 1. ✓
First combine mod 2 and mod 3: need x odd and x≡2(mod3).
x=2k+1 and 2k+1≡2(mod3)⟹2k≡1(mod3)⟹k≡2(mod3).
So k=3j+2, x=6j+5. Combined: x≡5(mod6).
Now combine with mod 5: x≡5(mod6) and x≡3(mod5).
x=6j+5 and 6j+5≡3(mod5)⟹6j≡−2≡3(mod5)⟹j≡3(mod5).
So j=5n+3, x=6(5n+3)+5=30n+23.
Answer: x≡23(mod30).
Problem 2. Find all n such that 7∣n2+1.
n2≡−1≡6(mod7).
Check n=1,…,6: 1,4,2,2,4,1 (squares mod 7). None equal 6.
So 7∤n2+1 for any n. No solutions.
Problem 3. How many integers in {1,…,1000} are coprime to 1000?
1000=23×53.
ϕ(1000)=1000(1−21)(1−51)=1000×21×54=400.
Problem 4. Prove: if p is an odd prime, ax2+bx+c≡0(modp) has at most 2 solutions mod p.
Complete the square (valid since p is odd, so 2 is invertible): reduce to y2≡d(modp). This has 0 or 2 solutions (since Z/pZ is a field — every nonzero element is either a quadratic residue with 2 roots or a non-residue with 0 roots). ■
The connection to look for
When a problem involves "find all n such that [some expression] is an integer," you're usually solving a Diophantine equation. When it involves "find all n such that [some expression] is divisible by m," you're solving a congruence. The GCD is the gatekeeper to both.
The full problem set — mixing these techniques — is in GCD and LCM Problems.