Prove that $1^2 3^2 5^2 \cdots (p-4)^2 (p-2)^2 \equiv (-1)^{(p+1)/2} \pmod p$. Let $p$ be an odd prime number. Prove that $$1^2 3^2 5^2 \cdots (p-4)^2 (p-2)^2 \equiv (-1)^{(p+1)/2} \pmod p.$$ I know I can use Wilson's Theorem somehow. It would make sense if I could show that all the factors $(p-2k)^2$ is congrunt to $-1 \pmod p$ because then the product would result in congruent to $(-1)^{(p+1)/2}\pmod p$. But I'm not quite sure how to go about that. Can you help?
EDIT: Okay, I think I have it now. So, using that $1^2 \equiv (-1) \cdot 1 \cdot (p-1)$, $3^2\equiv (-1) \cdot 3 \cdot (p-3)$ etc., we get $$1^2 3^2 5^2 \cdots (p-4)^2 (p-2)^2 \equiv (-1) \cdot 1 \cdot (p-1) \cdot (-1) \cdot 3 \cdot (p-3) \cdots (-1) \cdot (p-4) \cdot (4) \cdot (-1) \cdot (p-2) \cdot 2  \pmod p \Leftrightarrow \\ 1^2 3^2 5^2 \cdots (p-4)^2 (p-2)^2 \equiv (-1)^{(p-1)/2}(p-1)! \equiv (-1)^{(p+1)/2} \pmod p.$$ Correct?
 A: I will give you an answer that does not use the 'trick' $a^2\equiv(-1)\cdot a\cdot(p-a)$, which was given in a comment above. (Ok, this is less beautiful but, honestly, this was the first thing I thought and I think I would not have found the 'trick'.)
I will use the fact that $2\cdot4\cdot6\cdots2n=2^n\cdot n!$, hoping to prove the congruency by rewriting $1^2\cdot3^2\cdots(p-2)^2$ as the multiplicative inverse of $2^2\cdot4^2\cdots(p-1)^2$. (Note that Wilson's theorem says this is indeed its inverse.)
It remains to compute $2^2\cdot4^2\cdots(p-1)^2\pmod p$, which is $2^{p-1}\left[\left(\frac{p-1}2\right)!\right]^2\equiv\left[\left(\frac{p-1}2\right)!\right]^2\pmod p$, using the fact $2\cdot4\cdot6\cdots2n=2^n\cdot n!$.
The following identity (sometimes called a generalisation of Wilson's theorem) can easily be deduced from Wilson's theorem:
$$(k-1)!\cdot(p-k)!\equiv(-1)^k\pmod p,$$
if $k\leq p$ and $p$ is odd. (To see how, write $(p-k)!=(p-k)(p-(k+1))(p-(k+2))\cdots(p-(p-1))\equiv(-1)^{p-k}\cdot k\cdot(k+1)\cdots(p-1)$. Also note that the case $k=1$ is the original theorem.)
Plugging in $k=\frac{p+1}2$ gives us
$$\left[\left(\frac{p-1}2\right)!\right]^2\equiv(-1)^{\frac{p+1}2}\pmod p,$$ which is exactly what we were looking for.
Our final answer is the multiplicative inverse of $(-1)^{\frac{p+1}2}$ which is clearly $(-1)^{\frac{p+1}2}$ since $(-1)^{\frac{p+1}2}\cdot(-1)^{\frac{p+1}2}\equiv1\pmod p$.
