During my research I came across this question :


**Question:** What's the value of $x\_p=(\dfrac{p-1}{2})! \mod p$ when $p>3$ is prime ?


*Remark:* It's easy to see $x\_p^2 \mod p=(-1)^{\dfrac{p+1}{2}} \mod p$ with $x\_p\in [1;p-1] \cap \mathbb N$


But it's not easy to find if $x\_p \leq\dfrac{p-1}{2}$ or $x\_p> \dfrac{p-1}{2}$



1/2 Wilson's theorem
For the case $p\equiv 1\pmod{4}$, see the following paper of Chowla: On the class number of real quadratic fields. Proc. Nat. Acad. Sci. U.S.A. 47 (1961), 878. There the following is proved:


Let $h$ be the class number of $\mathbb{Q}(\sqrt{p})$, and let $\epsilon = (u+v\sqrt{p})/2$ be the fundamental unit of the corresponding ring of integers. Then $h$ is odd and
$$ 2\cdot \frac{p-1}{2}! \equiv (-1)^{(h+1)/2} u \pmod{p}.$$ 


One can find an exposition of this result (and related material) in the last chapter of Pollack's *Conversational Introduction to Algebraic Number Theory*.


