Solution
= Solution
For $a=2$, the least positive residues in <Gauss lemma (number theory)>[Gauss lemma for quadratic residues] are simply $2,4,\ldots,p-1$. The number exceeding $p/2$ is
$$
s=\frac{p-1}2-\left\lfloor\frac p4\right\rfloor.
$$
For $p\equiv1,3,5,7\pmod8$, respectively, this count is even, odd, odd, even. Substituting these parities into the lemma gives
$$
\boxed{\left(\frac2p\right)=\begin{cases}1,&p\equiv1,7\pmod8,\\-1,&p\equiv3,5\pmod8.\end{cases}}
$$