Sum of Legendre symbols is 0? I have a question regarding this sum:
\begin{equation}
\sum_{k=1}^{p-1}k\left(\frac{k}{p}\right)
\end{equation}
where $(k/p)$ is the Legendre symbol mod $p$, for $p>3$. I shall prove that
\begin{equation}
\sum_{k=1}^{p-1}k\left(\frac{k}{p}\right)\equiv0
\end{equation} 
(mod $p$). To do this I took a generator $g$ of $G=(Z/pZ)^*$ and wrote
\begin{equation}
\sum_{k=1}^{p-1}k\left(\frac{k}{p}\right)=\sum_{j=1}^{p-1}g^j(-1)^j=-g\frac{1+g^p}{1+g}
\end{equation}
(mod $p$) and I don't know that to do now. I read here "Sum of Legendre symbols" that the conclusion follows somehow using Fermat's Little Theorem, but I can't see how.
 A: The geometric series has initial term $-g$, common ratio $-g$, and $p-1$ terms, so its sum is 
$$
(-g)\dfrac{1-(-g)^{p-1}}{1-(-g)}=-g\frac{1-(-g)^{p-1}}{1+g} \, .
$$
Now, $(-g)^{p-1} \equiv 1\pmod{p}$ by FLT, so the sum of the series is $0$ whenever $g \ne -1$ in $\mathbb{Z}/p\mathbb{Z}$.
A: Here is an interesting result.  Let $p>3$ be a prime number.  Define
$$S(p)=\sum_{k=1}^{p-1}k\left(\frac{k}{p}\right).$$
We assert that for $p\equiv 1\pmod{4}$,
$$S(p)=0.$$
Note that
$$S(p)=\sum_{k=1}^{p-1}(p-k)\left(\frac{p-k}{p}\right)=\sum_{k=1}^{p-1}(p-k)\left(\frac{-k}{p}\right).$$
If $p\equiv1\pmod{4}$, then $\left(\frac{-1}{p}\right)=1$ so $\left(\frac{-k}{p}\right)=\left(\frac{-1}{p}\right)\left(\frac{k}{p}\right)=\left(\frac{k}{p}\right)$.  Hence
$$S(p)=\sum_{k=1}^{p-1}(p-k)\left(\frac{k}{p}\right)=p\sum_{k=1}^{p-1}\left(\frac{k}{p}\right)-S(p).$$
Since $\sum_{k=1}^{p-1}\left(\frac{k}{p}\right)=0$ (there are as many quadratic residues as quadratric non-residues), we get $S(p)=0-S(p)=-S(p)$, so $S(p)=0$.  
I don't know what happens if $p\equiv3\pmod{4}$.  According to this other question, it is conjectured that $S(p)<0$ in such cases, but nobody has a proof.
