Recently I was looking up on Wilson's theorem to find out what are the values of a function $f(n) \equiv (n-1) \pmod{n}$ for any $n$. So I know that for prime numbers $\geq $ 2 that would be -1, and it looks like for composite values $(n-1)! \equiv 0 \pmod{n} $ unless $n = 4$. So I'm wondering, why does $4$ stick out?
-
1How is 5! mod 6 not 0? 5! contains 6 as a factor. – TASPlasma Jun 18 '17 at 21:36
-
1Maybe it is a typo, and the case $n=4$ sticks out. – Batominovski Jun 18 '17 at 21:36
-
Yeah, it is. Sorry – toxing Jun 18 '17 at 21:37
-
See https://math.stackexchange.com/questions/164852/if-n-ne-4-is-composite-then-n-divides-n-1 – TASPlasma Jun 18 '17 at 21:38
2 Answers
For $n>4$ and composite, $(n-1)!\equiv0\pmod{n}$.
First suppose $n$ can be written as $n=ab$, with $a\ne b$, and both $>1$.
Then $a$ and $b$ appear as factors of $(n-1)!$, so we are done.
Otherwise $n=p^2$, for a prime $p$. Since $n>4$, we have $p\ge3$ and $(n-1)!$ contains $p$ and $2p$ as factors.
Thus the only exceptional case is $n=4$, where $3!\equiv 2\pmod{4}$.
The case $n=1$ is not exceptional either.

- 238,574
If $n>4$ is composite, then either $n$ has an odd prime divisor $p$ so $p<\frac{2n}{p}<n$, or $n$ is a power of $2$, in which case $2<\frac{n}{2}<n$. In the first case $2n=p\left(\frac{2n}{p}\right)$ divides $(n-1)!$, so that $n$ divides $(n-1)!$, while in the second case $n=2\left(\frac{n}{2}\right)$ is a factor of $(n-1)!$. This does not work for $n=4$, as $2=\frac{n}{2}$.

- 49,629