fermats-little-theorem-proof
Wed Apr 01 2026
Statement
Let p be any prime and a any integer not divisible by p. Then
ap−1≡1(modp)
There's a more general form, ap≡a(modp), which includes the trivial case when p∣a. Both are equivalent, the second just doesn't require the coprimality condition.
Proof
Setup
Consider (Z/pZ)∗={1,2,…,p−1} and pick some a∈Z/pZ∗. Define a map f:Z/pZ∗→Z/pZ∗ by
f(x)=a⋅x
So f sends the group elements {1,2,…,p−1} to {a⋅1,a⋅2,…,a⋅(p−1)}.
f is a bijection
Surjective: Since p is prime, a−1 exists and is unique in modp. For any element a⋅i in the image, there's a pre-image a−1⋅a⋅i=i.
Injective: Suppose f(i)=f(j), meaning a⋅i≡a⋅j(modp). Multiply both sides by a−1:
a−1⋅a⋅ii≡a−1⋅a⋅j(modp)≡j(modp)
So i=j⟹f(i)=f(j).
f is NOT an automorphism. It doesn't preserve the group operation, i.e., f(i⋅j)=f(i)⋅f(j). All f does is permute the group elements.
The punchline
Since f is a bijection on a finite set, it's just a permutation. The product of all group elements stays the same:
i∈Z/pZ∗∏ii∈Z/pZ∗∏ii∈Z/pZ∗∏i1≡i∈Z/pZ∗∏f(i)(modp)≡i∈Z/pZ∗∏a⋅i(modp)≡ap−1i∈Z/pZ∗∏i(modp)≡ap−1(modp)
The last step cancels ∏i from both sides. Every element in (Z/pZ)∗ is coprime to p, so it's invertible.
Extension to Euler's theorem
This generalizes to Euler's theorem: aφ(m)≡1(modm) where gcd(a,m)=1. Replace (Z/pZ)∗ with Zm∗={x∈Zm:gcd(x,m)=1}. The map f(x)=a⋅x is still a bijection on this group, so the product argument carries over, just with φ(m) elements instead of p−1.