Prove that an integer $n > 1$ is prime if and only if the following holds: $(n − 1)! ≡ −1 \pmod n$

234 Views Asked by At

So I am trying to prove this as follows:

we know a number $p$ is prime if and only if $Z_p$ is a field. More specifically, if $\forall x \in Z_p,\exists ! x^{-1}\in Z_p$ such that $xx^{-1}\equiv 1\pmod p)$. So considering $(p-1)!$, every term in the factorial from $2$ to $p-2$ has an inverse, so we can replace them both with $1$. So the congruence becomes

$1\times $(...$\frac{p-1}{2}$ times 1...)$\times (p-1)\equiv (p-1)\equiv -1 \pmod p$.

Is there any problem with this proof?