Wilson Theorem
A primality criterion for p.
Formula
Variables
Example
Holds iff p is prime
How it works
Wilson’s Theorem says that when p is prime, the product of all nonzero residue classes modulo p, namely 1·2·3·…·(p−1), leaves a remainder of p−1, which is the same as −1 modulo p. The reason is that every number from 1 to p−1 has a unique multiplicative inverse modulo p, and these inverses pair up to give factors of 1, except for the self-inverse elements 1 and p−1; their product is −1. This makes the theorem both a deep structural fact about the arithmetic of primes and a useful one-line test for primality.
When to use it
Use this when you need a theoretical primality criterion or when proving properties of modular inverses and residue classes. It is especially useful in advanced number theory proofs, though it is rarely practical for large-number primality testing because computing (p−1)! directly is expensive.
Worked example, step by step
Check p = 5. 1! = 1 2! = 1×2 = 2 ≡ 2 mod 5 3! = 1×2×3 = 6 ≡ 1 mod 5 4! = 1×2×3×4 = 24 ≡ 4 mod 5 So (5−1)! = 24 ≡ 4 mod 5. Since 4 ≡ −1 mod 5, we have (5−1)! ≡ −1 mod 5. Therefore Wilson’s Theorem holds for p = 5.
Common mistakes to avoid
- Forgetting that the theorem is stated modulo p, so the result p−1 is the same as −1 only after reducing mod p
- Trying to use the theorem as a fast computational primality test for large p, even though factorial growth makes it inefficient
- Assuming the theorem works for composite p; it is an iff statement, so failure of the congruence means p is not prime
Did You Know?
Wilson's theorem gives a perfect but hopelessly slow test for whether a number is prime.
Share this formula
More in Number Theory
View allEuclidean Algorithm
BasicRecursively finds the greatest common divisor.
Modular Congruence
Basica and b have the same remainder when divided by m.
Fermat's Little Theorem
AdvancedHolds when p is prime and gcd(a,p)=1.
Euler's Totient
AdvancedCounts integers up to n coprime to n.
Prime Number Theorem
AdvancedApproximates the number of primes below x.
LCM from GCD
BasicLeast common multiple via the greatest common divisor.