$p$ divides the sum of the quadratic residues $\bmod p$ Could you help me at the following exercise?
Show that, if $p>3$ is a prime,then $p$ divides the sum of the quadratic residues $\bmod p$.
 A: Let $S$ be the sum of the quadratic residues. As $k$ runs from $1$ to $p-1$, the number $k^2$ runs (twice) over the quadratic residues modulo $p$. Thus
$$2S\equiv 1^2+2^2+\cdot +(p-1)^2.$$
By using the formula for the sum of the first $n$ consecutive squares, we find that
$$2S\equiv \frac{(p-1)(p)(2p-1)}{6}\pmod{p},$$
and therefore 
$$12S\equiv (p-1)(p)(2p-1)\pmod{p}.$$
Since $p$ divides $(p-1)(p)(2p-1)$ but $p\gt 3$, it follows that $p$ divides $S$.
Another way: Let $g$ be a primitive root of $p$. Then the quadratic residues are congruent, modulo $p$, to $g^2,g^4,\dots, g^{p-1}$. Thus if $S$ is the sum of the quadratic residues, we have
$$S\equiv g^2+g^4+\cdots +g^{p-1}\pmod{p}.$$
Multiply both sides by $g^2-1$. We get
$$(g^2-1)S\equiv g^2(g^{p-1}-1)\pmod{p}.$$
By Fermat's Theorem, the right-hand side is congruent to $0$ modulo $p$. And if $p\gt 3$, then $g^2\not\equiv 1\pmod{p}$, and therefore $S\equiv 0\pmod{p}$. 
A: Let the quadratic residues mod $p$ be $a_1,a_2,a_3,\cdots$ and the sum is $S$.
Clearly(prove) $p|S\iff p|1^2+2^2+\cdots+(p-1)^2$
The sum is $$\frac{(p-1)p(2p-1)}{6}$$
and we are done.
A: No sum formulas are needed for this one. The non-zero quadratic residues form a subgroup $Q_p$ of the multiplicative group $\Bbb{Z}_p^*$. Because $p>3$ the residue class of $4$ is a quadratic residue. Because $\overline{4}\in Q_p$, we have, by basic properties of groups, that $x$ will range over $Q_p$ as $4x$ does. So in the field $\Bbb{Z}_p$ we have
$$
S=\sum_{x\in Q_p}x=\sum_{x\in Q_p}4x=4S.
$$
This gives the equation (still in the field $\Bbb{Z}_p$)
$$
0=4S-S=3S\quad\Longrightarrow\quad S=0,
$$
as $3$ is also a unit in the field.
Mapping everything back to integers gives then $S\equiv 0\pmod p$ as requested.
