MathorynMathematical Formula Database

Number Theory

Wilson's Theorem

An integer p>1p>1 is prime if and only if (p−1)!+1(p-1)!+1 is divisible by pp. It is an elegant (though slow) characterisation of primes. It is used in number theory proofs and as a theoretical test of primality.

(p−1)!≡−1(modp)(p-1)!\equiv-1\pmod p
LaTeX(p-1)!\equiv-1\pmod p

Variables

pp
prime number

Example

Check for p=7p=7.

  1. 6!=720=7⋅102+66!=720=7\cdot102+6, and 6≡−1(mod7)6\equiv-1\pmod7.

Answer: 720≡−1(mod7)720\equiv-1\pmod 7.

Related formulas