A variant n+1 primality test

Last time I discussed the n1 and n+1 primality tests. Recall that the n1 test says that n is prime if there exists an aZn such that

an11(modn)a(n1)/p1(modn)

for all primes p which divide n1.

The n+1 can be stated in a similar form, and says that n is prime if it is odd and there exists an a(Z[d]) with (dn)=1 such that

an+11(modn)a(n+1)/p1(modn)

for all primes p which divide n+1.

I state it in this form to make the connection with the n1 test, but I’ve done a little sleight-of-hand in the presentation. In the first test a is a unit of Zn, while in the second test a is a unit of Z[d] (not Zn[d]). That is, the norm of a in Q(d) is 1; this is a rather restrictive condition. In fact, when d<3 the only units of Z[d] are ±1, and both of these will fail the second condition since (n+1)/p will be even for some p.

When d is positive and squarefree the situation is a little better in that there are an infinite number of units in Z[d]. However, these units are all of the form ±ϵk for some fundamental unit ϵ:=x+yd (this may be found by solving Pell’s equation x2dy2=1). If the fundamental unit doesn’t satisfy the conditions then any power of it will also necessarily fail, so for any given value of d there is essentially only one possible choice of a which could work. On the upside, one could simply look up this choice in a table when d is small; e.g., for d:=3 one should use a:=2+3.

So that’s an unfortunate condition which isn’t present in the n1 test, but it’s necessary to be able to use Fermat’s theorem in Z[d], which implies that if p is prime and a has norm 1 then

ap(d/p)1(modp),

and more generally

ape1(p(d/p))1(modpe).

Now we’re ready to prove that the primality test works as stated. Let ordn,d(a) denote the order of a in (Zn[d]), so the two conditions of the primality test tell us that ordn,d(a)=n+1.

Say n has prime factorization i=1kpiei. By the Chinese remainder theorem, we have

Zn[d]i=1kZpiei[d],

so

n+1=ordn,d(a)=lcm(ordp1e1,d(a),,ordpkek,d(a))

and by Fermat’s theorem this divides

lcm(p1e11(p1(d/p1)),,pkek1(pk(d/pk))).

Since each pi is odd, this equals

=2lcm(p1e11p1(d/p1)2,,pkek1pk(d/pk)2)2i=1kpiei1pi(d/pi)22ni=1kpi+12pi.

Now, if n has at least two distinct prime factors then this is at most

2n3+1235+125=45n.

Thus we conclude that n+14n/5, a contradiction since n is positive. Thus n must have just one prime factor; say n:=pe. Using Fermat’s theorem and the fact that (dp)=1 (otherwise (dn)1), we have

n+1=ordn,d(a)pe1(p+1)=n+pe1.

It follows that n+1pe11n/3, again a contradiction, unless pe1=1, i.e., e=1 and n=p 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 Fn2 working in the background.