Fermat's theorem: if a is not divisible by p, then $a^{p-1} \equiv 1 \pmod p$
Since $\varphi(p)=p-1$, this is a special case of Euler's theorem. If $(a,m)=1$, then $a^{\varphi(m)}\equiv 1 \pmod m$.
Proof: Let $c_1,.....,c_{\varphi(m)}$ be a reduced residue system $(mod\text{ } m)$ and let a be prime to m. Then $ac_1,.....,ac_{\varphi(m)}$ is also a reduced residue system $(mod\text{ } m)$, and therefore
$$\prod_{i=1}^{\varphi(m)}ac_i \equiv \prod_{i=1}^{\varphi(m)}c_i \pmod m$$
Why is the latter true?
$\varphi(p)$ counts the number of elements ina reduced residue system mod p