Solution (source code)

= Solution

Since $n>1$, its <factorial> is even, so $(n!)^2+1$ is odd and its <prime divisor> $p$ is odd. Also $p$ cannot divide $n!$, since it would then divide1. Modulo $p$,
$$
(n!)^2\equiv-1.
$$
Raise this equation to the <integer> power $(p-1)/2$. <Fermat's little theorem> gives
$$
1\equiv(n!)^{p-1}\equiv(-1)^{(p-1)/2}\pmod p.
$$
As $p$ is odd, $1$ and $-1$ are distinct <residues>. Thus the exponent is even, and
$$
\boxed{p\equiv1\pmod4.}
$$