Sub topic 12
Wilson's Theorem for Factorial Remainders
Prerequisites and the main result
Assume you can factor integers, identify prime numbers, and work with remainders and congruences. Recall that a factorial is a product such as 5! = 5 × 4 × 3 × 2 × 1.
Wilson's theorem states:
For a prime number p,
(p − 1)! ≡ −1 (mod p)
Since −1 has remainder p − 1 modulo p, this is equivalent to:
(p − 1)! leaves remainder p − 1 when divided by p.
For example:
12! ≡ −1 (mod 13)
Therefore, 12! leaves remainder 12 when divided by 13.
Why the theorem works
Consider the nonzero remainders modulo a prime p:
1, 2, 3, ..., p − 1
Every number in this list has a multiplicative inverse modulo p. An inverse of a is a number b such that:
a × b ≡ 1 (mod p)
Most numbers pair with a different inverse. For example, modulo 7:
2 × 4 = 8 ≡ 1 (mod 7)
The only numbers that are their own inverses satisfy:
a² ≡ 1 (mod p)
This gives:
a² − 1 ≡ 0 (mod p)
(a − 1)(a + 1) ≡ 0 (mod p)
For prime p, this means a ≡ 1 or a ≡ −1 (mod p). Thus, the only self-inverses are 1 and p − 1.
All other factors in (p − 1)! cancel in inverse pairs, leaving:
1 × (p − 1) ≡ −1 (mod p)
That proves Wilson's theorem.
Using Wilson's theorem
Use the theorem directly when the factorial ends at one less than a prime.
| Expression | Prime modulus | Remainder |
|---|---|---|
| 6! | 7 | 6 |
| 10! | 11 | 10 |
| 12! | 13 | 12 |
A short Python check is:
import math
for p in [7, 11, 13]:
remainder = math.factorial(p - 1) % p
print(p, remainder)The output is:
7 6
11 10
13 12Wilson's theorem also tests primality. If n is prime, then (n − 1)! leaves remainder n − 1 modulo n. However, this test is usually slow for large n because calculating a large factorial is expensive. CAT questions use the theorem mainly to simplify a known factorial remainder.
Common errors
- Apply the theorem only when the modulus p is prime.
- The factorial is (p − 1)!, not p!.
- The answer may be written as −1 or as p − 1. Both represent the same remainder class.
- Wilson's theorem does not say that every factorial has remainder −1 modulo its modulus.
Exercise
Find the remainder when 16! is divided by 17.
Show answer
Since 17 is prime, Wilson's theorem gives 16! ≡ −1 (mod 17). The remainder is 16.