I came across this problem and I believe Lagrange's theorem is the key to its solution. The question is:
Let $p$ be an odd prime. Prove that there is some integer $x$ such that $x^2 \equiv −1 \pmod p$ if and only if $p \equiv 1 \pmod 4$.
I appreciate any help. Thanks.
Hint: When $p$ is prime: $-1 \equiv (p-1)!\pmod p$ and when $p\equiv 1\pmod 4$, $(p-1)!\equiv\left[\left(\frac{p-1}{2}\right)!\right]^2\pmod p$
Alternatively, you can use the fact that a polynomial of degree $n$ has at most $n$ roots, modulo $p$, and that $x^{p-1}-1 = \left(x^{\frac{p-1}2}-1\right)\left(x^{\frac{p-1}2}+1\right)$ is known to have $p-1$ roots, modulo $p$, so $x^{\frac{p-1}2}+1$ must have a root, $r$, and then $r^{\frac{p-1}4}$ has the property that $r^2\equiv -1\pmod p$