Fermat's Little Theorem

Let pZp \in \Z and a prime number and aZa \in \Z such that gcd(a,p)=1\mathrm{gcd}(a,p) = 1 then ap11(modp)a^{p-1} \equiv 1 \pmod{p}. Furthermore for all aZa \in \Z, we have apa(modp)a^p \equiv a \pmod{p}

Proof

We are calculating in Zp\Z_p.

First let us show that 1a,2a,3a,...,(p1)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 rasa(modp)r\cdot a \equiv s\cdot a \pmod{p}. Since gcd(a,p)=1(a,p) = 1, then rs(modp)r \equiv s \pmod{p} by a preceding lemma.

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

(1a)(2a)(3a)...((p1)a)123...(p1)(1\cdot a) (2 \cdot a) (3 \cdot a) ... ((p-1) \cdot a) \equiv 1\cdot 2 \cdot 3 \cdot ... \cdot (p-1)
123...(p1)ap1123...(p1)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
...
p1<pp-1 < p and pp is prime, so gcd(p1,p)=1(p-1,p) = 1

It follows that:

ap1=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
    ap1=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 a00pap(modp)a \equiv 0 \equiv 0^p \equiv a^p \pmod{p}

Pseudo-primes

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

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