Fermat's Little Theorem

Let p∈Zp \in \Z and a prime number and a∈Za \in \Z such that gcd(a,p)=1\mathrm{gcd}(a,p) = 1 then ap−1≡1(modp)a^{p-1} \equiv 1 \pmod{p}. Furthermore for all a∈Za \in \Z, we have ap≡a(modp)a^p \equiv a \pmod{p}

Proof

We are calculating in Zp\Z_p.

First let us show that 1⋅a,2⋅a,3⋅a,...,(p−1)⋅a1\cdot a, 2 \cdot a, 3 \cdot a, ..., (p-1) \cdot a are all different (modp)\pmod{p}.

Let rr and ss be such that r⋅a≡s⋅a(modp)r\cdot a \equiv s\cdot a \pmod{p}. Since gcd(a,p)=1(a,p) = 1, then r≡s(modp)r \equiv s \pmod{p} by a preceding lemma.

Since they are all different, then 1⋅a,2⋅a,3⋅a,...,(p−1)⋅a1\cdot a, 2 \cdot a, 3 \cdot a, ..., (p-1) \cdot a is a permutation of non-zero elements of Zp\Z_p

(1⋅a)(2⋅a)(3⋅a)...((p−1)⋅a)≡1⋅2⋅3⋅...⋅(p−1)(1\cdot a) (2 \cdot a) (3 \cdot a) ... ((p-1) \cdot a) \equiv 1\cdot 2 \cdot 3 \cdot ... \cdot (p-1)
1⋅2⋅3⋅...⋅(p−1)⋅ap−1≡1⋅2⋅3⋅...⋅(p−1)1\cdot 2 \cdot 3 \cdot ... \cdot (p-1) \cdot a^{p-1} \equiv 1\cdot 2 \cdot 3 \cdot ... \cdot (p-1)

2<p2 < p and pp is prime, so gcd(2,p)=1(2,p) = 1
3<p3 < p and pp is prime, so gcd(3,p)=1(3,p) = 1
...
p−1<pp-1 < p and pp is prime, so gcd(p−1,p)=1(p-1,p) = 1

It follows that:

ap−1=1(modp)a^{p-1} = 1 \pmod{p}

For the second statement we consider two cases:

  1. if gcd(a,p)=1(a,p)= 1

    then we just show that
    ap−1=1(modp)a^{p-1} = 1 \pmod{p}
    ap=a(modp)a^{p} = a \pmod{p}

  2. if gcd(a,p)≠1(a,p)\neq 1

    then gcd(a,p)=p(a,p) = p
    therefore a≡0≡0p≡ap(modp)a \equiv 0 \equiv 0^p \equiv a^p \pmod{p}

Pseudo-primes

If pp is an odd prime, then 2p−1≡1(modp)2^{p-1} \equiv 1 \pmod{p}

If nn is composite and bn−1≡1(modm)b^{n-1} \equiv 1 \pmod{m} we say that nn is pseudo-prime base b.