Given a prime number $p>2$, calculate $\left(\frac{p-1}{2} \right)! \mod p$

81 Views Asked by At

Since $(p-1)!\mod p = -1$ and $$(p-1)!\mod p \\ = \prod_{k=1}^{\frac{p-1}{2}}k(p-k) \mod p\\ = (-1)^\frac{p-1}{2} \prod_{k=1}^{\frac{p-1}{2}}k^2 \mod p\\ = (-1)^\frac{p-1}{2}\left(\left(\frac{p-1}{2}\right)!\right)^2 \mod p$$

we have $$(-1)^\frac{p-1}{2}\left(\left(\frac{p-1}{2}\right)!\right)^2 \mod p = -1$$

which further induces $$\left(\left(\frac{p-1}{2}\right)!\right)^2 \mod p=\begin{cases}1, \text{ if }\frac{p-1}{2}\text{ is odd}\\ p-1, \text{ otherwise} \end{cases}$$

If $\frac{p-1}{2}$ is odd then $\left(\frac{p-1}{2}\right)!\mod p$ can be $1$ or $p-1$. If it is even, there are also two possible values.

My problem is

  1. how to solve $x^2\mod p = p-1$

  2. determine correct value of $\left(\frac{p-1}{2}\right)!$