Wilson’s theorem

First known appearance in a work of Ibn al-Haytham (965-1039). Stated by Leibniz in an unpublished paper around 1670. Conjectured by John Wilson before 1770. First proved by Lagrange in 1771.

    \begin{equation*} \boxed{p \text{ is prime if and only if } (p-1)!\equiv -1\pmod p} \end{equation*}

i.e. if p is prime, p divides into (p-1)!+1

Proof: The factors 1,2,3,\dots,p-1 of (p-1)! all have inverses \mod p, so each is cancelled by its own inverse except the factors that are inverse to themselves. These are 1 and p-1, and no others – because if x^2\equiv 1\pmod{p} then:

    \[x^2-1\equiv (x-1)(x+1)\equiv 0 \pmod{p},\]

i.e. p divides (x-1)(x+1). But then p divides x-1 or x+1, by the prime divisor property, so

    \[x\equiv 1 \pmod{p} \quad \text{or} \quad x\equiv -1 \pmod{p}.\]

Thus (p-1)!\equiv 1\times 1\times\dots\times 1\times -1\equiv -1 \pmod{p}.


In 1957, F.G. Elston generalized Wilson’s theorem:
Let p be prime and 0 \leq r \leq p-1.
Then r!(p-1-r)!+(-1)^r \equiv 0 \pmod p

Leave a Reply

Your email address will not be published.