If p is an odd prime, prove that $1^2 \times 3^2 \times 5^2 \cdots \times (p-2)^2 \equiv (-1)^{(p+1)/2}\pmod{p}$

You can start with Wilson's theorem, $(p-1)! \equiv -1 \pmod{p}.$ Rearrange the factorial thus, with $p=2m+1,$ $$-1 \equiv 1(p-1)2(p-2) \ldots m(p-m) \equiv 1(-1)2(-2) \ldots m(-m) \equiv 1^22^2 \ldots m^2(-1)^m \pmod{p}.$$

So we have shown

$$1^22^2 \ldots m^2 \equiv (-1)^{m+1} $$

or, noting that $m=(p-1)/2,$ in terms of $p$

$$1^12^2 \ldots \left( \frac{p-1}{2} \right)^2 \equiv (-1)^{(p+1)/2}.$$

Now we construct the product on the LHS, so consider first $2^24^2 \ldots (p-1)^2$ and factor out $2^{2p-2}$ then use Fermat, $2^{p-1} \equiv 1 \pmod{p}.$

You should now have the result for the product with the even numbers, use that along with Wilson's theorem again to prove the desired result for the product with the odd numbers.


$p=2m+1$,

we can write $1\equiv -(p-1)\pmod p$,

Now write $1^2 \times 3^2 \dots(p-2)^2$ as $1\times(-(p-1))\times 3\times(-(p-3)\dots(p-2)(-(P-(p-2)))$, $\implies 1^2 \times 3^2 \dots(p-2)^2 = 1\times(-(p-1))\times3\times(-(p-3)\dots(p-2)(-(P-(p-2)))\\\equiv-1^m (p-1)! \equiv-1^{m+1}\pmod p$ wilson theorem, $1^2 \times 3^2 \dots(p-2)^2\equiv-1^{(p+1)/2} \pmod p$ (as taken $p=2m+1$)

similar for another case