TITLE: example, that Wilson's Theorem is not necessarily true
QUESTION [7 upvotes]: Show by an example, that Wilson's Theorem is not necessarily true if $p$ is not prime. (In fact, it is not hard to show that it is never true if $p$ is not prime, but I am not asking you to do that.)
My solve :
let $p$ is not prime like $4$ so $(4 - 1)! = 3!  = 2 \pmod 4 \neq -1 \pmod 4$.
Is that correct?

REPLY [3 votes]: As Mr. Brooks pointed out, Wilson's theorem is an if-and-only-if theorem, which makes it different from Fermat's little theorem. Fermat's condition holds for all primes and some composites, so the fact that a given number satisfies the condition is not a guarantee of primality.
By contrast, a number that meets Wilson's condition is guaranteed to be a prime number. (However, the calculations are more laborious, which diminishes the practical value of Wilson's theorem).
So, if I understand your question correctly, you can choose any composite number $n$ (preferably a small one, like 4) and do the calculations to show that $(n - 1)! \equiv 2$ or $0 \pmod n$.
But maybe what you're looking for is something a little bit more general that still stops short of proving the whole theorem.
For example, if $n$ is an even composite number, then $(n - 1)!$ is also an even composite number. If $(n - 1)! \equiv -1 \pmod n$, that would mean $(n - 1)!$ is odd, which is a contradiction.
Or let's say $n = pq$, the product of two distinct odd primes. Since $p < q < n$ (or $q < p < n$, doesn't make much difference), it follows that both $p$ and $q$ are divisors of $(n - 1)!$. Therefore $(n - 1)! \equiv 0$, not $-1$, $\pmod n$.