When is $(p - 2)! \equiv 1 (\bmod p)$

150 Views Asked by At

I want to show when the following is true for $p$ a prime number. $(p - 2)! \equiv 1 \pmod p$. Could someone help me prove this? It worked for $p = 2$, $p = 3$, $p = 5$, so I believe it may work for all primes but I need to prove it. I don't know how to apply Wilson's or Fermat's theorem to this. I tried to rewrite it as $(p - 1 - 1)! \equiv 1 \pmod p$ but I still couldn't see how to apply Wilson's theorem to it. Could someone help me?

1

There are 1 best solutions below

10
On

From Wilson's theorem, $(p-1)!\equiv-1\pmod p$. Also, $p-1\equiv-1\pmod p$. Therefore

$$(p-1)!=(p-2)!(p-1)\equiv-(p-2)!\equiv-1\implies(p-2)!\equiv1\pmod p$$

for every prime $p$.

For non-primes, the question is actually rather more interesting. We can use a similar approach to the proof of Wilson's theorem. Suppose $n=ab$ with $2\le a<b\le n-2$. Then both $a$ and $b$ appear as factors in $(n-2)!$, so $(n-2)!\equiv 0$. If there is no such decomposition, then $n=q^2$ for some prime $q$. If $q=2$, then $n=4$ and hence $(n-2)!\equiv 2$. Otherwise, $q\ge3$ so $(q+1)(q-3)\ge0\to2q\le n-3$, and hence $q,2q$ appear as factors in $(n-2)!$. Thus we have:

$$(n-2)!\equiv\begin{cases}1,&n\mbox{ is prime}\\2,&n=4\\0,&n\ne4\mbox{ is composite}\\\end{cases}\pmod n.$$