Statement of Fermat’s Little Theorem
Theorem
Fermat’s Little Theorem: If p is a prime and a is an integer not divisible by p, then:
ap−1≡1(modp)
For any integer a and prime p:
ap≡a(modp)
This form works even when p∣a (both sides are 0modp).
Examples
- p=5, a=2: 24=16≡1(mod5)
- p=7, a=3: 36=729≡1(mod7)
- p=11, a=2: 210=1024≡1(mod11)
Examinable Proof
The Proof Strategy
We show that a,2a,3a,…,(p−1)a modulo p form a permutation of 1,2,3,…,p−1.
Step 1: Non-zeroness
Each ia(modp) is non-zero for 1≤i≤p−1.
Reason: p∤a by hypothesis, and p∤i since 1≤i<p and p is prime.
Thus p∤ia.
Step 2: Distinctness
If ia≡ja(modp) for 1≤i,j≤p−1, then i=j.
Proof: ia≡ja(modp) means p∣(i−j)a.
Since p∤a and p is prime, Euclid’s lemma gives p∣(i−j).
But ∣i−j∣≤p−2<p, so ∣i−j∣=0 and i=j.
Step 3: Permutation Argument
The numbers 1,2,…,p−1 are p−1 distinct non-zero residues modulo p.
By Steps 1 and 2, a,2a,…,(p−1)a are also p−1 distinct non-zero residues modulo p.
Therefore:
{a,2a,…,(p−1)a}={1,2,…,p−1}(modp)
Step 4: Product Equality
Taking products:
a⋅2a⋅3a⋅⋯⋅(p−1)a≡1⋅2⋅3⋅⋯⋅(p−1)(modp)
This simplifies to:
ap−1⋅(p−1)!≡(p−1)!(modp)
Step 5: Cancellation
Since 1≤(p−1)!<p! and (p−1)! is the product of integers 1 through p−1, none of which are divisible by p, we have p∤(p−1)!.
Thus gcd(p,(p−1)!)=1.
By the cancellation property of modular arithmetic:
ap−1≡1(modp)
Applications
Modular Exponentiation
To compute akmodp where p is prime:
- Reduce k modulo p−1: k=q(p−1)+r with 0≤r<p−1
- Then ak≡ar(modp)
Example: Compute 3100mod7.
100=16⋅6+4, so 3100≡34=81≡4(mod7).
Primality Testing
If there exists a with p∤a such that ap−1≡1(modp), then p is not prime.
Note: The converse is not true in general. A Carmichael number is composite but satisfies an−1≡1(modn) for all a coprime to n.
Diffie-Hellman Key Exchange
Two parties agree on:
- A large prime p
- A generator g of (Z/pZ)×
Each picks a secret:
- Alice picks secret a, sends gamodp
- Bob picks secret b, sends gbmodp
Shared secret: (ga)b=(gb)a=gabmodp.
Security relies on the difficulty of computing discrete logarithms.
Fermat’s Theorem and Wilson’s Theorem
Wilson’s Theorem
(p−1)!≡−1(modp) iff p is prime.
Connection
In our proof of Fermat’s Little Theorem, we used that (p−1)! is coprime to p. Wilson’s theorem gives its exact value.
Generalisations
Euler’s Theorem
For a coprime to n: aϕ(n)≡1(modn), where ϕ(n) is Euler’s totient function.
When n is prime, ϕ(n)=n−1, giving Fermat’s Little Theorem.
Summary
- Fermat’s Little Theorem: ap−1≡1(modp) for prime p and p∤a
- Proof uses permutation argument and cancellation
- Applications: fast modular exponentiation, cryptography (Diffie-Hellman), primality testing
- Generalised by Euler’s theorem to composite moduli