For prime n, pair each nonzero residue with its inverse; only ±1 are self-inverse, yielding Wilson theorem. Conversely, if (n−1)!≡−1(modn), every 1≤a<n is a unit (otherwise a common divisor would divide the left side and n but not −1), so n is prime.