TITLE: $3^2 \ 5^2 \ldots (p-2)^2 \equiv (-1)^{\frac{p+1}{2}} \ (\mathrm{mod} \ p)$
QUESTION [5 upvotes]: Possible Duplicate:
Why is the square of all odds less than an odd prime $p$ congruent to $(-1)^{(p+1)/(2)}\pmod p$? 

Why is $3^2 \  5^2 \ldots (p-2)^2 \equiv (-1)^{\frac{p+1}{2}} \ (\mathrm{mod} \ p)$, where $p$ is an odd prime?
I can't seem to figure it out. Any help would be appreciated. Thanks!

REPLY [5 votes]: Since $a\equiv -(p-a)\pmod{p}$, we can write
\begin{align}
3^2 \cdot  5^2 \cdots (p-2)^2&\equiv \left(3\cdot 5\cdots (p-2)\right)\times\left((p-3)\cdot (p-5)\cdots 2\right)\times (-1)^{(p-3)/2}\\
&\equiv (-1)^{(p-3)/2}(2\cdot 3\cdots (p-2))\cdot (p-1)\cdot (p-1)\\
&\equiv (-1)^{(p-1)/2}(p-1)!\\
&\equiv (-1)^{(p+1)/2}\pmod{p},
\end{align}
where in the third step we introduced a factor of $(p-1)(p-1)\equiv -1\cdot -1\equiv 1$, and in the last step we used Wilson's Theorem.