$n \in \Bbb N$ and $p$ is prime and odd, Suppose $n \in \Bbb N$ and $p$ is prime and odd, how to prove :
$$\sum_{a=1}^{p-1}a^n \equiv
\begin{cases}
p-1\pmod p & \text{if }p-1\mid n, \\
0 \pmod p & \text{otherwise}.  \\
\end{cases}$$
 A: Using Fermat's Little Theorem, $a^{p-1}\equiv1\pmod p$ if $(a,p)=1$
$\implies a^n\equiv1\pmod p$ if $(p-1)\mid n$
So, $\sum_{1\le a\le p-1 }a^n\equiv \sum_{1\le a\le p-1 }1\pmod p\equiv p-1$  if $(p-1)\mid n$
If $(p-1)\not\mid n,$ 
since the sets of reduced residue classes    $\{1, 2,\cdots, (p − 1)\}$
and $\{g, 2g,\cdots, (p − 1)g\}$ are the same  if $(g,p)=1$,
 then $\sum_{1\le a\le p-1 }a^n ≡\sum_{1\le a\le p-1}(g\cdot a)^n$
So, $p\mid (g^n-1)\sum_{1\le a\le p-1 }a^n$
If $g$ is set to be a primitive root of $p,$
$ord_pg=p-1\implies g^n\equiv 1 \pmod p\iff (p-1)\mid n$
As $(p-1)\not\mid n,g^n\not\equiv 1 \pmod p\implies p\not\mid (g^n-1)$
$\implies p\mid \sum_{1\le a\le p-1 }a^n\iff \sum_{1\le a\le p-1 }a^n\equiv0\pmod p$
A: Suppose: 
$$\,(p-1)\nmid n\;:\;\,\Longrightarrow\,\,\,\text{ the map}\;\Bbb F_p^*\to\Bbb F_p^*\;,\;\;x\to x^n$$ 
is an automorphism (of the cyclic group $\,\Bbb F_p^*\,$) , and then $\,\forall\,x\in\Bbb F_p^*\;\exists\,!\,y\in\Bbb F_p^*\,\,\,s.t.\,\,\,x=y^n\,$ , so 
$$S:=\sum_{a=1}^{p-1}a^n=\sum_{k=1}^{p-1}k=\frac{p-1}{2}p=0$$
Suppose now: 
$$\,(p-1)\mid n\,:\,\iff n=k(p-1)\,\,,\,\,k\in\Bbb N\Longrightarrow\,\,\forall\,x\in\Bbb F_p^*\;,\;\;x^n=\left(x^{p-1}\right)^k=1^k=1$$  by Fermat's Little Theorem , so
$$S=\sum_{a=1}^{p-1}a^n=\sum_{a=1}^{p-1}1=p-1$$ 
