# For which primes $p$ is $(p-6)! \equiv 1 \mod p$ defined?

For which primes $p$ is $(p-6)! \equiv 1 \mod p$ defined?

I brute forced it by repeatedly trying lots of primes and ended up with $p=7, p=17$. Does anyone have a better method to do this?

• Hint: $(p-1)! = -1 \mod p$ – Vladislav Kharlamov May 10 '18 at 23:04
• Adding to what @VladislavKharlamov said, this is known as Wilson's Theorem. – Mr Pie May 11 '18 at 1:16

We rewrite our expression as: $$(p-1)!(p-5)^{-1}(p-4)^{-1} \ldots (p-1)^{-1} \equiv 1 \mod p$$ Using Wilson's theorem we get: $$-(p-5)^{-1}\ldots(p-1)^{-1} \equiv 1 \mod p$$
But $$(p-5)^{-1}(p-4)^{-1} \ldots (p-1)^{-1} \equiv (-5!)^{-1} \mod p$$ Then, need find $p$ : $$-(-5!)^{-1} \equiv 1 \mod p \Leftrightarrow 5! \equiv 1 \mod p$$
• In other words, $p$ must divide $5!-1 = 119$. Not too many of those... – Robert Israel May 10 '18 at 23:23