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
    $\begingroup$ See mathoverflow.net/questions/121678/… $\endgroup$
    – dhy
    Mar 29, 2019 at 13:19
  • $\begingroup$ He talks about the case $p \mod 4=3$ what about the other case ? $\endgroup$
    – Dattier
    Mar 29, 2019 at 13:29
  • $\begingroup$ See OEIS sequence A004055 for programs and the first 9999 terms. $\endgroup$ Mar 29, 2019 at 14:04
  • $\begingroup$ If you change the generator $b$ and replace it (for example) by $1/b$ then the sign you are interested in changes. So I think in the case p=1 mod 4, it does not really make sense to ask about this sign, as there is no canonical generator of $\mathbb{F}_p^{\times} $ $\endgroup$ Mar 29, 2019 at 14:43
  • $\begingroup$ Nevertheless you could define a kind of canonical square root of -1 by using a decomposition $p=a^2+b^2$, say $a/b$ with $a <b $. But you see it depends on some choices, which could turn out to be arbitrary $\endgroup$ Mar 29, 2019 at 14:51

2 Answers 2


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.


See the paper by Mordell: The congruence (p−1/2)!≡±1 (mod p). Amer. Math. Monthly 68 1961 145–146.

  • $\begingroup$ And $x_p=+-\sqrt{-1}$ when $p \mod 4=1$ $\endgroup$
    – Dattier
    Mar 29, 2019 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.