Suppose we have a prime \(p\), if we take modulo 4, then there are four possibilities, \((1 \mod 4)\), \((2 \mod 4)\), \((3 \mod 4)\) and \((4 \mod 4)\). Since \(p\) is even only when 2, then \(p\) cannot be \((2 \mod 4)\) or \((4 \mod 4)\) except when 2. To prove \(x^2 ≡ -1 \mod p\) is solvable if and only if \(p = 2\) or \(p ≡ 1 \mod 4\), we just need to show that there is no solution when:
If \(p ≡ 3 \mod 4\), then \(p = 4k + 3\), which would also mean:
Since \(x^2 ≡ -1 \mod p\):
but also:
So \(1 ≡ -1 \mod p\), that's possible when \(p=2\), but not when \(p=3 \mod 4\). If \(p ≡ 1 \mod 4\), then \(p = 4k + 1\) for some positive integer k. Thus, \((p - 1)/2\) is even. By Wilson's Theorem:
If we expand:
Since \(p - x ≡ -x \mod p\):
Let's take the negative sign out:
The second half is the same size as the first and they are both even, so \(l\) is even:
which means:
Thus, \(x^2 ≡ -1 \mod p\) has the solution \(x = ((p - 1)/2)!\) when \(p ≡ 1 \mod 4\).