Solution (source code)

= Solution

For an odd <prime number> $p$, the <Legendre symbol> is
$$
\left(\frac xp\right)=
\begin{cases}
0,&p\mid x,\\
1,&x\not\equiv0\pmod p\text{ is a <quadratic residue>},\\
-1,&x\text{ is a <quadratic nonresidue>}.
\end{cases}
$$
If $p\nmid x$, <multiplicativity of the Legendre symbol> gives
$$
\left(\frac xp\right)\left(\frac{x^{-1}}p\right)
=\left(\frac1p\right)=1.
$$
Both factors belong to $\{1,-1\}$, so they are equal. Thus $(x^{-1}/p)=(x/p)$.