Modular Mathematics, Wilson's Theorem

Wilson's Theorem

If p is prime, (p-1)! mod p is -1.

Group each nonzero element with its inverse.  These become 1 and go away.  This is fine except for values of x that are their own inverses.  In other words, x2 = 1.  We know there are only two square roots, 1 and -1, so after inverses pair off and go away, -1 is left.  This is a special case of a more general theorem in group theory.

Another proof uses a primitive root r.  since order doesn't matter, we are multiplying r1 × r2 × … × rp-1.  The exponent is the sum of the integers from 1 to p-1, which is p×(p-1)/2.  We know r to the (p-1)/2 is -1, and raising that to the p still gives -1.