This site is supported by donations to The OEIS Foundation.

# Wilson's theorem

Wilson's theorem concerns a relationship between factorials and prime numbers. Gottfried W. Leibniz knew of it before John Wilson and Edward Waring came along.

Theorem W1. (Wilson) The congruence $(n-1)!\equiv -1\mod n$ holds true if and only if $n$ is prime. Put another way, the number $(n-1)!+1$ is a multiple of $n$ only when $n$ is prime.

Proof. If $n$ is composite, then it has at least one prime factor $1 . For $n=4$ , we see that $3!\equiv 2\mod 4$ . For all higher composite $n$ , we see that the number $(n-1)!=\prod _{i=1}^{n-1}i$ is a product that runs through every prime factor of $n$ as well as other composite numbers repeating a lot of those same prime factors, and therefore $(n-1)!\equiv 0\mod n$ not –1.

The case of the prime number 2 is disposed of easily enough by examination, leaving us only the odd primes to concern ourselves with. We can also dispose of 3 by examination. The only divisors of an odd prime $p$ are 1 and itself, hence $\gcd(j,p)=1$ for all $1 . For each $j$ , there is precisely one integer $1 such that $jk\equiv 1\mod p$ . This means that each integer from 2 to $p-2$ can be paired off such that their product is 1 more than a multiple of $p$ , and therefore $\prod _{i=2}^{p-2}i\equiv 1\mod p$ . This falls short of the factorial, as it leaves out the pair consisting of 1 and $p-1$ , and we see that $1\times (p-1)\equiv -1\mod p$ , and therefore $(p-1)!$ satisfies the congruence specified by the theorem. □ 

So if we take a prime number, such as 7, we will find that the factorial of the number one less than that prime is one less than a multiple of that prime, such as is the case with 6! + 1 = 721, which is 103 times 7 (see A060371 and A007619).

There are of course many ways to prove the theorem. Decades ago, Bolker gave a proof using the algebra of polynomials and invoking Fermat's little theorem.