Prove that if $n$ is not divisible by $5$, then $n^4 \equiv 1 \pmod{5}$

Solution 1:

$$n^4-1 = (n-1)(n+1)(n^2+1)$$ The factors $n-1$ and $n+1$ take care of $n \equiv \pm 1 \mod 5$, while if $n \equiv \pm 2 \mod 5$, $n^2 + 1 \equiv 2^2 + 1 \equiv 0 \mod 5$.

Solution 2:

Product of 5 consecutive integer numbers is of course divisible by $5$, so $5|(n-2)(n-1)n(n+1)(n+2)$. If $5\not|n,$ then from primality of $5$ we have \begin{align*} 5|(n-2)(n-1)(n+1)(n+2) & = (n^2-1)(n^2-4)\\ & = n^4 - 5n^2 +4\\ & = n^4 - 1 - 5(n^2 - 1) \end{align*} so $5|n^4-1$.