Solution (source code)

= Solution

Because $I$ and $A$ commute, the matrix binomial theorem gives
$$
(I+A)^p=\sum_{j=0}^p\binom pjA^j.
$$
For prime $p$, every intermediate coefficient $\binom pj$ is divisible by $p$, proving the <prime-power binomial congruence for a matrix>
$$
(I+A)^p\equiv I+A^p\pmod p.
$$

For
$$
A=\begin{pmatrix}0&-1\\1&0\end{pmatrix},
\qquad A^2=-I,
$$
one has $(I+A)^2=2A$ and $(I+A)^4=-4I$. If $p=4k+1$, then
$$
(I+A)^p=(-4)^k(I+A)
\equiv I+A,
$$
so $(-4)^k\equiv1\pmod p$. If $p=4k-1$, then $A^p=-A$ and
$$
(I+A)^p=(-4)^k(I+A)^{-1}
=\frac{(-4)^k}{2}(I-A)
\equiv I-A,
$$
so $(-4)^k\equiv2\pmod p$.

By <Euler criterion>, $(\frac2p)\equiv2^{(p-1)/2}\pmod p$. In either case the preceding congruence gives $(\frac2p)=(-1)^k$. Since $(p^2-1)/8$ has the same parity as $k$ for $p=4k\pm1$, this is the <second supplementary law for quadratic reciprocity>
$$
\boxed{\left(\frac2p\right)=(-1)^{(p^2-1)/8}.}
$$