(n-1)!=1 x 2 x 3 x … x (n-1)
(n-1)! \equiv -1\pmodn
exactly when n is a prime number. In other words, any integer n > 1 is a prime number if, and only if, (n − 1)! + 1 is divisible by n.[1]
The theorem was first stated by Ibn al-Haytham . Edward Waring announced the theorem in 1770 without proving it, crediting his student John Wilson for the discovery.[2] Lagrange gave the first proof in 1771.[3] There is evidence that Leibniz was also aware of the result a century earlier, but never published it.[4]
For each of the values of n from 2 to 30, the following table shows the number (n − 1)! and the remainder when (n − 1)! is divided by n. (In the notation of modular arithmetic, the remainder when m is divided by n is written m mod n.)The background color is blue for
prime values of n, gold for composite values.2 | 1 | 1 | |
3 | 2 | 2 | |
4 | 6 | 2 | |
5 | 24 | 4 | |
6 | 120 | 0 | |
7 | 720 | 6 | |
8 | 5040 | 0 | |
9 | 40320 | 0 | |
10 | 362880 | 0 | |
11 | 3628800 | 10 | |
12 | 39916800 | 0 | |
13 | 479001600 | 12 | |
14 | 6227020800 | 0 | |
15 | 87178291200 | 0 | |
16 | 1307674368000 | 0 | |
17 | 20922789888000 | 16 | |
18 | 355687428096000 | 0 | |
19 | 6402373705728000 | 18 | |
20 | 121645100408832000 | 0 | |
21 | 2432902008176640000 | 0 | |
22 | 51090942171709440000 | 0 | |
23 | 1124000727777607680000 | 22 | |
24 | 25852016738884976640000 | 0 | |
25 | 620448401733239439360000 | 0 | |
26 | 15511210043330985984000000 | 0 | |
27 | 403291461126605635584000000 | 0 | |
28 | 10888869450418352160768000000 | 0 | |
29 | 304888344611713860501504000000 | 28 | |
30 | 8841761993739701954543616000000 | 0 |
As a biconditional (if and only if) statement, the proof has two halves: to show that equality does not hold when
n
n
Suppose that
n
q
2\leqq<n
q
n
k
n=qk
(n-1)!
-1
{n}
(n-1)!
-1
{q}
(n-1)!\equiv-1\pmod{n}
(n-1)!=nm-1=(qk)m-1=q(km)-1
m
(n-1)!
q
2\leqq\leqn-1
(n-1)!=(n-1) x (n-2) x … x 2 x 1
q
(n-1)!\equiv0\pmod{q}
(n-1)!\equiv-1\pmod{n}
n
In fact, more is true. With the sole exception of the case
n=4
3!=6\equiv2\pmod{4}
n
(n-1)!
n
n
n=ab
2\leqa<b<n
a
b
(n-1)!=(n-1) x (n-2) x … x 2 x 1
(n-1)!
ab=n
n
q
2q<q2=n
q
2q
(n-1)!
n
(n-1)!
The first two proof below use the fact that the residue classes modulo a prime number are a finite field—see the article Prime field for more details.[5]
The result is trivial when
p=2
p
p\geq3
p
a
a-1
a
a\equiva-1\pmod{p}
a\equiv\pm1\pmod{p}
\pm1
(p-1)!
p
For example, for
p=11
Again, the result is trivial for p = 2, so suppose p is an odd prime, . Consider the polynomial
g(x)=(x-1)(x-2) … (x-(p-1)).
g has degree, leading term, and constant term . Its roots are 1, 2, ..., .
Now consider
h(x)=xp-1-1.
h also has degree and leading term . Modulo p, Fermat's little theorem says it also has the same roots, 1, 2, ..., .
Finally, consider
f(x)=g(x)-h(x).
f has degree at most p − 2 (since the leading terms cancel), and modulo p also has the roots 1, 2, ..., . But Lagrange's theorem says it cannot have more than p − 2 roots. Therefore, f must be identically zero (mod p), so its constant term is . This is Wilson's theorem.
Sp
(p-1)!
Cp
Sp
Cp
np=(p-2)!
(p-2)!\equiv1\pmodp.
(p-1)!\equivp-1\equiv-1\pmodp,
In practice, Wilson's theorem is useless as a primality test because computing (n − 1)! modulo n for large n is computationally complex, and much faster primality tests are known (indeed, even trial division is considerably more efficient).
Used in the other direction, to determine the primality of the successors of large factorials, it is indeed a very fast and effective method. This is of limited utility, however.
Using Wilson's Theorem, for any odd prime, we can rearrange the left hand side ofto obtain the equalityThis becomesorWe can use this fact to prove part of a famous result: for any prime p such that p ≡ 1 (mod 4), the number (−1) is a square (quadratic residue) mod p. For this, suppose p = 4k + 1 for some integer k. Then we can take m = 2k above, and we conclude that (m!)2 is congruent to (−1) (mod p).
Wilson's theorem has been used to construct formulas for primes, but they are too slow to have practical value.
Wilson's theorem allows one to define the p-adic gamma function.
Gauss proved[6] thatwhere p represents an odd prime and
\alpha
The Disquisitiones Arithmeticae has been translated from Gauss's Ciceronian Latin into English and German. The German edition includes all of his papers on number theory: all the proofs of quadratic reciprocity, the determination of the sign of the Gauss sum, the investigations into biquadratic reciprocity, and unpublished notes.