On this page
In number theory, Wilson's theorem gives a fascinating condition that is true for prime numbers and prime numbers alone. It states that if *p* is a prime, the factorial *(p - 1)!* is exactly one less than a multiple of *p*.
Written in the language of modular arithmetic, it says:
*(p - 1)! ≡ -1 (mod p)*
The theorem was first stated by the polymath Ibn al-Haytham around 1000 AD. However, the first formal proof was published by Joseph-Louis Lagrange in 1771.
What is Wilson's theorem?
The theorem connects primes and factorials. A prime number *p* has no divisors other than 1 and itself. When we look at the numbers 1, 2, 3, ..., *p* - 1, every number in this list has a unique "multiplicative inverse" modulo *p*. This means that for every number *a*, there is another number *b* in the list such that *a × b ≡ 1 (mod p)*.
The only numbers that are their own inverses are 1 and *p* - 1 (which is equivalent to -1). Because all the other numbers pair up to make 1, multiplying all of them together leaves just 1 × (*p* - 1), which is -1 modulo *p*.
How to check Wilson's theorem for p = 5 and p = 7?
Let's check the theorem with small primes.
For p = 5:
We calculate (5 - 1)! = 4! = 1 × 2 × 3 × 4 = 24.
We divide 24 by 5. The closest multiple of 5 is 25.
24 is exactly 25 - 1, so 24 ≡ -1 (mod 5).
For p = 7:
We calculate (7 - 1)! = 6! = 1 × 2 × 3 × 4 × 5 × 6 = 720.
We divide 720 by 7. We know that 7 × 103 = 721.
720 is exactly 721 - 1, so 720 ≡ -1 (mod 7).
If you want to explore more properties of factorials and combinatorics, read our guide on arrangements with letters together.
How to solve a remainder problem with Wilson's theorem?
Wilson's theorem is a powerful shortcut for finding the remainder of large factorials divided by primes. Here is a standard remainder problem:
Question: Find the remainder when 14! is divided by 17.
State Wilson's theorem for *p* = 17:
16! ≡ -1 (mod 17)
Expand 16! to reveal 14!:
16 × 15 × 14! ≡ -1 (mod 17)
Simplify 16 and 15 modulo 17:
16 is 1 less than 17, so 16 ≡ -1 (mod 17).
15 is 2 less than 17, so 15 ≡ -2 (mod 17).
Substitute these into the equation:
(-1) × (-2) × 14! ≡ -1 (mod 17) 2 × 14! ≡ -1 (mod 17)
Replace -1 with an equivalent positive number that is easy to divide by 2. We know -1 ≡ 16 (mod 17):
2 × 14! ≡ 16 (mod 17)
Divide both sides by 2:
14! ≡ 8 (mod 17)
The remainder when 14! is divided by 17 is 8.
Let's look at another classic variation. What if you need to find the remainder of a factorial that is slightly further away from the prime?
Question: Find the remainder when 9! is divided by 11.
State Wilson's theorem for *p* = 11:
10! ≡ -1 (mod 11)
Expand 10! to reveal 9!:
10 × 9! ≡ -1 (mod 11)
Simplify 10 modulo 11:
10 is exactly 1 less than 11, so 10 ≡ -1 (mod 11).
Substitute this into the equation:
(-1) × 9! ≡ -1 (mod 11)
Multiply both sides by -1:
9! ≡ 1 (mod 11)
The remainder when 9! is divided by 11 is 1. This shows how you can quickly work backward from *(p - 1)!* to find the value of *(p - 2)!*. You can even repeat the process to find *(p - 3)!*, though the algebra takes a few more steps.
For more clever calculation tricks, you can check out the sum of all numbers formed from given digits.
If you are studying number theory and find yourself stuck on proofs, the Fermi Problem Library has worked problems with a step-by-step solver that explains the reasoning rather than printing an answer. It breaks down complex theorems into logical steps, helping you understand the "why" behind the math.



