Mathwords logoMathwords

Wilson's Theorem — Definition, Formula & Examples

Wilson's Theorem says that for any prime number pp, the factorial (p1)!(p-1)! leaves a remainder of p1p-1 when divided by pp. Equivalently, (p1)!+1(p-1)! + 1 is divisible by pp, and this property holds only for primes.

An integer p>1p > 1 is prime if and only if (p1)!1(modp)(p-1)! \equiv -1 \pmod{p}. This provides a necessary and sufficient condition for primality, though it is computationally impractical for large numbers due to the cost of computing factorials.

Key Formula

(p1)!1(modp)    p is prime(p-1)! \equiv -1 \pmod{p} \iff p \text{ is prime}
Where:
  • pp = A positive integer greater than 1 being tested for primality
  • (p1)!(p-1)! = The factorial of p − 1, i.e., the product 1 × 2 × 3 × ⋯ × (p−1)

How It Works

To apply Wilson's Theorem, compute (p1)!(p-1)! and check whether dividing it by pp gives a remainder of p1p - 1 (which is the same as 1(modp)-1 \pmod{p}). If it does, pp is prime. If you already know pp is prime, you can use the theorem to simplify modular factorial expressions without computing the full factorial. For composite numbers, (p1)!0(modp)(p-1)! \equiv 0 \pmod{p} in most cases, because pp's factors appear within the product 12(p1)1 \cdot 2 \cdots (p-1).

Worked Example

Problem: Verify Wilson's Theorem for p = 7.
Compute (p−1)!: Calculate 6! = 1 × 2 × 3 × 4 × 5 × 6.
6!=7206! = 720
Divide by p: Divide 720 by 7 and find the remainder.
720=7×102+6720 = 7 \times 102 + 6
Check the condition: The remainder is 6, which equals p − 1 = 7 − 1. In modular terms, 6 ≡ −1 (mod 7).
6!1(mod7)6! \equiv -1 \pmod{7} \checkmark
Answer: Since 6! ≡ −1 (mod 7), Wilson's Theorem is confirmed and 7 is indeed prime.

Why It Matters

Wilson's Theorem is a cornerstone result in number theory that connects factorials and primes in a surprising way. It appears in math competitions (AMC, AIME, olympiads) where you need to evaluate large factorials modulo a prime, and it serves as a theoretical foundation for deeper results in abstract algebra and cryptography.

Common Mistakes

Mistake: Thinking Wilson's Theorem says (p-1)! ≡ 1 (mod p) instead of −1.
Correction: The correct congruence is (p−1)! ≡ −1 (mod p). A remainder of −1 mod p is the same as a remainder of p − 1, not 1.