Last time I discussed the and primality tests. Recall that the test says that is prime if there exists an such that
for all primes which divide .
The can be stated in a similar form, and says that is prime if it is odd and there exists an with such that
for all primes which divide .
I state it in this form to make the connection with the test, but I’ve done a little sleight-of-hand in the presentation. In the first test is a unit of , while in the second test is a unit of (not ). That is, the norm of in is ; this is a rather restrictive condition. In fact, when the only units of are , and both of these will fail the second condition since will be even for some .
When is positive and squarefree the situation is a little better in that there are an infinite number of units in . However, these units are all of the form for some fundamental unit (this may be found by solving Pell’s equation ). If the fundamental unit doesn’t satisfy the conditions then any power of it will also necessarily fail, so for any given value of there is essentially only one possible choice of which could work. On the upside, one could simply look up this choice in a table when is small; e.g., for one should use .
So that’s an unfortunate condition which isn’t present in the test, but it’s necessary to be able to use Fermat’s theorem in , which implies that if is prime and has norm then
and more generally
Now we’re ready to prove that the primality test works as stated. Let denote the order of in , so the two conditions of the primality test tell us that .
Say has prime factorization . By the Chinese remainder theorem, we have
so
and by Fermat’s theorem this divides
Since each is odd, this equals
Now, if has at least two distinct prime factors then this is at most
Thus we conclude that , a contradiction since is positive. Thus must have just one prime factor; say . Using Fermat’s theorem and the fact that (otherwise ), we have
It follows that , again a contradiction, unless , i.e., and is prime.
I found this kind of argument in Prime Numbers and Computer Methods for Factorization (page 116). In that book it is applied to Lucas sequences, which simplifies some things, although can also obscure the group working in the background.