Solution (source code)

= Solution

<Euler's criterion> states
$$
\boxed{a^{(p-1)/2}\equiv\left(\frac ap\right)\pmod p.}
$$
For $p\nmid a$ the right side is $+1$ or $-1$. The displayed congruence also holds for $p\mid a$, since $p$ is odd and the exponent is positive.