1

After running some test on my computer I found that when you have a prime $p$, then $(p-1)! \textrm{ mod } p$ always equals to $p-1$ and that $(p-2)! \textrm{ mod } p$ always equals to $1$.

Why is this the case? (I don't need answers on both findings, just one as when I know that why $(p-2)! \textrm{ mod } p$ always equals to $1$ then just by multiplying it by $p-1$ we get $(p-1)! \textrm{ mod } p =p-1$ and vice versa).

3 Answers3

6

Wilson's theorem states ($n\ge 2$): $$(n-1)!\equiv -1\pmod{\! n}\iff n\text{ is prime},$$

which can be restated as ($n\ge 2$): $$(n-2)!\equiv 1\pmod{\! n}\iff n\text{ is prime},$$

because $$(n-1)!\equiv -1\iff (n-2)!(n-1)\equiv -1$$

$$\iff (n-2)!(-1)\equiv -1\stackrel{:(-1)}\iff (n-2)!\equiv 1\pmod{\! n}$$

user26486
  • 11,519
0

A bit late answer, but still...

$\forall 0 < k < p, \exists! l : kl \equiv 1 \pmod{p}$

$k^2 \equiv 1\pmod{p}, \Rightarrow k \equiv \pm 1 \pmod{p}$

So if you take all remainders there will be 1, -1, and pairs of mutually reciprocal, so product will be -1.

0

The polynomial $x^{p-1}-1$ has roots in $\Bbb Z_p^\times$, we may write $$x^{p-1}-1=(x-1)(x-2)\cdot\ldots\cdot(x-(p-1))$$ Comparing coefficitents we get that $$-1=(-1)^{p-1}(p-1)!=(p-1)!$$ Noticing that $p-1\equiv_p -1$, we can divide both sides by $-1$ to get $$(p-2)!\equiv_p 1$$

cansomeonehelpmeout
  • 14,020
  • 3
  • 29
  • 55