<s>[INST] Prove that if $p>2$ is prime then $\left(\prod_{k=1}^{p-1}k^k\right)^2\equiv (-1)^{\frac{p+1}2}\pmod p.$ Prove that if $p>2$ is prime then 
$$\left(\prod_{k=1}^{p-1}k^k\right)^2\equiv (-1)^{\frac{p+1}2}\pmod p.$$
I find this by computer but cannot prove it, thank you!
 [/INST] Let's deal with the stuff inside the square first. Since $p-1$ is even we have that:
$\prod_{k=1}^{p-1} k^k \equiv \left(\prod_{k=1}^{\frac{p-1}{2}} k^k\right) \left(\prod_{k=1}^{\frac{p-1}{2}} (-k)^{p-k}\right) = (-1)^{\frac{p-1}{2}} \prod_{k=1}^{\frac{p-1}{2}}k^p \equiv (-1)^{\frac{p-1}{2}}\prod_{k=1}^{\frac{p-1}{2}}k \quad\bmod p$.
So $\left(\prod_{k=1}^{p-1} k^k\right)^2 \equiv \left(\left(\frac{p-1}{2}\right)!\right)^2 \bmod p$.
Now if $p\equiv 1 \bmod 4$ then:
$\left(\left(\frac{p-1}{2}\right)!\right)^2 \equiv (p-1)! \equiv -1 \equiv (-1)^{\frac{p+1}{2}} \bmod p$.
Whereas if $p \equiv 3 \bmod 4$ then:
$\left(\left(\frac{p-1}{2}\right)!\right)^2 \equiv -(p-1)! \equiv 1 \equiv (-1)^{\frac{p+1}{2}} \bmod p$.
</s>