Fermat's Little Theorem

Theorem
If $$p$$ is a prime number and $$p \nmid n$$, then $$n^{p-1} \equiv 1 \pmod p$$.

Corollary 1
If $$p$$ is a prime number, then $$n^p \equiv n \pmod p$$.

Corollary 2
If $$p$$ is a prime number, then:
 * $$n^{p-1} \equiv \left[{p \nmid n}\right] \pmod p$$

where $$\left[{\cdots}\right]$$ is Iverson's convention.

Proof of Theorem
Consider the sequence of integers $$n, 2n, 3n, \dots, (p-1)n$$.

Note that none of these integers are congruent modulo $p$ to the others.

If this were the case, we would have $$a n \equiv b n \pmod p$$ for some $$1 \le a < b \le p-1$$.

Then as $$\gcd \left\{{n, p}\right\} = 1$$, and we can cancel the $n$, we get $$a \equiv b \pmod p$$ and so $$a = b$$.

Also, since $$p \nmid n$$ and $$p \nmid c$$, for any $$1 \le c \le p-1$$, then by Euclid's Lemma $$p \nmid c n$$ for any such $$c n$$, which means $$c n \not \equiv 0 \pmod p$$.

Thus, each integer in the sequence can be reduced modulo $$p$$ to exactly one of $$1, 2, 3, \ldots, p-1$$.

So $$\left\{{1, 2, 3, \ldots, p-1}\right\}$$ is the set of least positive residues modulo $$p$$.

So, upon taking the product of these congruences, we see that $$n \times 2n \times 3n \times \dots \times (p-1)n \equiv 1 \times 2 \times 3 \times \cdots \times (p-1) \pmod p$$.

This simplifies to $$n^{p-1} \times (p-1)! \equiv (p-1)! \pmod p$$.

Since $$p \nmid (p-1)!$$, we can cancel $(p-1)!$ from both sides, leaving us with $$n^{p-1}\equiv 1 \pmod p$$.

Alternative Proof
By Prime Not Divisor then Coprime, $$p \nmid n \implies p \perp n$$ and Euler's Theorem can be applied.

Thus $$n^{\phi \left({p}\right)} \equiv 1 \pmod p$$.

But from Euler Phi Function of a Prime, $$\phi \left({p}\right) = p \left({1 - \frac 1 p}\right) = p - 1$$ and the result follows.

Proof of Corollary 1
There are two cases:


 * If $$p \backslash n$$, then $$n^p \equiv 0 \equiv n \pmod p$$.


 * Otherwise, $$p \nmid n$$.

Then, by Fermat's Little Theorem, $$n^{p-1} \equiv 1 \pmod p$$.

Multiplying both sides by $$n$$, then by Congruence of Product we have $$n^p \equiv n \pmod p$$.

Proof of Corollary 2
If $$p \nmid n$$ then from the main result $$n^{p-1} \equiv 1 \pmod p$$.

If $$p \backslash n$$ then $$p \backslash n^{p-1}$$ and $$n^{p-1} \equiv 0 \pmod p$$ by definition.

Hence the result by definition of Iverson's convention.

It dates from 1640.