Solution (source code)

= Solution

<Euler criterion> states that
$$
\boxed{\left(\frac ap\right)\equiv a^{(p-1)/2}\pmod p}.
$$
When $p\nmid a$, the power is congruent to $+1$ or $-1$, according as $a$ is or is not a <quadratic residue>.