Wilson's theorem

For an integer j≥2:

(j−1)!+1≡0(modj)⟺j is prime.

Equivalently, j∣(j−1)!+1 precisely when j is prime (and trivially when j=1).

Consequence: This gives a primality criterion — in principle it detects primes, though computing (j−1)! makes it impractical for large j.but

Related: prime counting function, prime number theorem.