Square root of minus one modulo a prime (source code)

= Square root of minus one modulo a prime
{title2=$x^2\equiv-1\pmod p$}

The congruence is soluble exactly for $p=2$ or $p\equiv1\pmod4$. For odd $p$, <Fermat's little theorem> applied to a prospective root <forces> $(p-1)/2$ even. Conversely, when $p\equiv1\pmod4$, pair opposite factors in $(p-1)!$ and use the <Wilson theorem> to obtain $(((p-1)/2)!)^2\equiv-1\pmod p$.