Solution (source code)

= Solution

Write $\chi(a)=(a/p)$. If $p\mid a$, the claimed identity has both sides zero. Otherwise let $\epsilon=\chi(a)\in\{1,-1\}$. Applying the <Euler criterion> gives
$$
\chi(\epsilon a)\equiv(\epsilon a)^{(p-1)/2}
\equiv\epsilon^{(p-1)/2}\chi(a)=\epsilon^{(p+1)/2}\pmod p.
$$
Both sides are in $\{1,-1\}$, which are distinct <residue> classes because $p$ is odd. Therefore the <modular congruence> is an equality:
$$
\boxed{\left(\frac{\left(\frac ap\right)a}p\right)
=\left(\frac ap\right)^{(p+1)/2}.}
$$