How does Wilson's theorem provide a test for prime numbers?

Created from Britannica articles using AI. AI can make mistakes, so verify using Britannica articles.

In number theory, Wilson’s theorem provides a definitive test for prime numbers based on the property that an integer p>1 is prime if and only if it divides the quantity (p−1)!+1.12

The theorem establishes this relationship in two ways:
* Primality: If p is a prime number, then (p−1)!+1 is divisible by p.1
* Converse: If n is a composite number, then (n−1)!+1 is not divisible by n.1

While this provides a mathematically absolute method to determine whether a number is prime, it is generally considered impractical for large numbers because calculating the factorial (n−1)! becomes computationally exhaustive as the value of n increases.1