Proof.
The statement is clear when

, so henceforth we assume
that

.
We first assume that

is prime and prove that

. If

then
the equation
has a unique solution

.
If

, then

, so

, so

or

, so

.
We can thus pair off the elements of

,
each with their inverse.
Thus
Multiplying both sides by

proves that

.
Next we assume that
and
prove that
must be prime. Suppose not, so that
is a composite number. Let
be a prime divisor
of
. Then
, so
. Also,
by assumption,
This is a contradiction, because a prime can not divide a number

and
also divide

, since it would then have to divide

.
SAGE Example 2.1
We use SAGE to create a table of triples; the first
column contains

, the second column contains

modulo

,
and the third contains

modulo

. Notice that the first columns contains a prime
precisely when the second and third columns are equal.
(The ... notation indicates indentation in SAGE; you should not type the dots
in explicitly.)
sage: for n in range(1,10):
... print n, factorial(n-1) % n, -1 % n
1 0 0
2 1 1
3 2 2
4 2 3
5 4 4
6 0 5
7 6 6
8 0 7
9 0 8