Use Wilson’s Theorem to show $(q!)^2+(-1)^q \equiv 0$ mod p

elementary-number-theorymodular arithmetic

Let $q=\frac{p-1}{2}$ and $p$ is an odd prime. Show that
$$(q!)^2+(-1)^q\equiv 0 \pmod{p}.$$

I know that I have to use Wilson's Theorem somehow, I am just completly lost at how to do so. Any help would be greatly appreciated.

Best Answer

A number $p \in \mathbb{N}$ is prime if and only if for all $1 \leq n \leq p$ $$ (n-1)!(p-n)!\equiv(-1)^n \pmod{p}. $$

This theorem can be easily proved with complete induction on $n$ and with Wilson's theorem. If you set $n=\frac{p+1}{2}$ here, the result is:

$p \in \mathbb{N}$, $p>2$ is prime if and only if $$\left(\left(\frac{p-1}{2}\right)!\right)^2 \equiv(-1)^{\frac{p+1}{2}} \pmod{p}.$$

This is what you want.

You can also prove your statement directly, as a hint, use that: $$\begin{aligned} p-1 &\equiv-1 \pmod{p}\\ p-2 &\equiv-2 \pmod{p}\\ & \hspace{2.25mm}\vdots \\ \frac{p+1}{2} &\equiv-\frac{p-1}{2} \pmod{p} \end{aligned}$$

Related Question