Closed form for $(p-n)!\pmod{p}$ where $p$ is prime

Does $(p-n)!\pmod{p}$ have a closed form for any $n>2$ when $p$ is prime?

  • $(p-0)!=0 \pmod{p}$

  • $(p-1)!=-1\pmod{p}$

  • $(p-2)!=1\pmod{p}$


Since $(p-1)! \equiv -1 \mod p$, $$(p-n)! \equiv \frac{(p-1)!}{\prod_{j=1}^{n-1} (p-j)} \equiv (-1)^{n-1} ((n-1)!)^{-1} \mod p$$


The only interesting case is $n=1$, which is Wilson's theorem.

The case $n=2$ follows from $n=1$ directly.

For the case $n=3$ one needs to know the multiplicative inverse of $p-2 \bmod p$, which is $(p-1)/2$. So, $(p-3)! \equiv (p-1)/2 \bmod p$.

For the case $n=4$ one needs to know the multiplicative inverse of $p-3 \bmod p$. Now $p=3t\pm1$, assuming $p\ne3$. Then $(p-4)! \equiv (p\mp 1)(p-1)/6\bmod p$.

I guess you could carry on but it seems to get messier...