# Using Wilson's Theorem

I'm working through an exercise which involves Wilson's Theorem:

Let $n \in \mathbb{Z}$ with $n>1$. Prove that n is a prime number if and only if $(n-2)!\equiv 1 \pmod n$

So far I have :

($\rightarrow$) Suppose n is a prime number, by Wilson's theorem we know that $(n-1)!\equiv -1 \pmod n$. If we divide $(n-1)$ from both sides we get $(n-2)! \equiv 1 \pmod n$.

I'm not really sure how to get started on the opposite direction. Any hints?

## 2 Answers

Hint: if $n$ is not prime then it has a prime divisor $k \leq n/2$. If $n \geq 4$ then $n/2 \leq n-2$ and so $k \mid (n-2)!$, which contradicts $(n-2)! \equiv 1 \pmod{n}$.

$n$ is a prime iff $(n-1)!\equiv -1 \bmod n$. That's Wilson's theorem.

The result follows because $n-1\equiv -1 \pmod n$ :

In one direction, just cancel $n-1$ on the left with $-1$ on the right of $(n-1)!\equiv -1$.

In the other direction, just multiply both sides of $(n-2)!\equiv 1$ by $-1$.