Fermat test with gaussian base and Gaussian pseudoprimes

The structure of the group $(\mathbb{Z}/n\mathbb{Z})^\star$ and Fermat's little theorem are the basis for some of best-known primality testing algorithms. Many related concepts arise: Euler's totient function and Carmichael's lambda function, Fermat pseudoprimes, Carmichael and cyclic numbers, Lehmer's totient problem, Giuga's conjecture, etc. In this paper, we present and study analogues to some of the previous concepts arising when we consider the underlying group $\mathcal{G}_n:=\{a+bi\in\mathbb{Z}[i]/n\mathbb{Z}[i] : a^2+b^2\equiv 1\ \textrm{$\pmod n$}\}$. In particular we characterize Gaussian Carmichael numbers via a Korselt's criterion and we present their relation with Gaussian cyclic numbers. Finally, we present the relation between Gaussian Carmichael number and 1-Williams numbers for numbers $n \equiv 3 \pmod{4}$. There are also no known composite numbers less than $10^{18}$ in this family that are both pseudoprime to base $1+2i$ and 2-pseudoprime.


Introduction
Most of the classical primality tests are based on Fermat's little theorem: let p be a prime number and let a be an integer such that p ∤ a, then a p−1 ≡ 1 (mod p). This theorem gives a possible way to detect non-primes: if for a certain a coprime to n, a n−1 ≡ 1 (mod n), then n is not prime. The problem is that the converse is false and there exists composite numbers n such that a n−1 ≡ 1 (mod n) for some a coprime to n. In this situation n is called pseudoprime with respect to base a (or a-pseudoprime). A composite integer n which is a pseudoprime to any base a such that gcd(a, n) = 1 is called a Carmichael number (or absolut pseudoprime).
Fermat theorem can be deduced from the fact that the units of Z/nZ form a subgroup of order n − 1 when n is prime. Associated to the subgroup (Z/nZ) ⋆ we can define the well-know Euler's totient function and Carmichael's lambda function which are defined in the following way: ϕ(n) := |(Z/nZ) ⋆ |, λ(n) := exp(Z/nZ) ⋆ .
It seems reasonable (and natural) to extend these ideas to other general groups G n . This extension leads to composite/primality tests according to the following steps: 1 o ) Compute f (n) = |G n | under the assumption that n is prime. 2 o ) Given n, if we can find g ∈ G n such that |g| ∤ f (n), then n is not prime. This idea is present in tests based in lucasian sequences [19] and elliptic curves [16]. Recent works have developed these concepts in other contexts. Pinch [14] considers primality tests based on quadratic rings and discuss the absolute pseudoprimes for them. Shettler [10] studies analogues to Lehmer's Problem Totient and Carmichael numbers in a PID. Steele [17] generalizes Carmichael numbers to number rings introducing Carmichael ideals in number rings and proving an analogue to Korselt's criterion for them.
Following these approaches, in this paper we consider the groups For these groups, we define the corresponding Euler and Carmichael functions and we study some of their properties. We also present the concepts of Gaussian pseudoprime and Gaussian Carmichael number presenting an explicit Korselt's criterion. Cyclic numbers, Lehmer's Totient Problem [3] and Giuga's conjecture [8] are also considered in this gaussian setting.
It is known that Carmichael numbers have at least three prime factors. We show that Gaussian Carmichael numbers with only two prime factors exist and we determine their form. Moreover, although there are gaussian pseudoprimes with respect to any base, if we combine our ideas with a classical Fermat test, we show that no number of the form 4k+3 smaller that than 10 18 passes both tests (for some particular bases). This strength is possible due to a relationship with 1-Williams numbers [19] that we make explicit.

Preliminaries
In this section we determine the order and structure of the group G n . We also show some elementary properties and relations between the Gaussian counterparts of Euler and Carmichael functions.
For any positive integer n we will denote by I n the ring of gaussian integers modulo n; i.e., Further, we will consider the group G n defined by Once we have defined the group we can define the following arithmetic functions: Note that Φ and ⋌ are the analogues to Euler's totient funtion and Carmichael's lambda functions, respectively. It is quite clear that if n = p r1 1 · · · p rs s , then G n ∼ = G p r 1 1 × · · · × G p rs s . As a consequence, if gcd(m, n) = 1, Φ(mn) = Φ(m)Φ(n) and ⋌(mn) = lcm(⋌(m), ⋌(n)). Hence, in order to study the group G n we can restrict ourselves to the case when n is a prime power. Proposition 1. Let p be a prime and let k > 0 be an integer. Then: if p = 2 and k = 1; Proof. We will focus only on the case p ≡ 3 (mod 4). In this case, it is well-known that G p ∼ = GF (p 2 ) ⋆ . Since G p is a subgroup of GF (p 2 ) ⋆ , it must be cyclic. Moreover, counting quadratic residues it can be seen that |G p | = p + 1 and, consequently, We can now apply the Fundamental Lemma in [7, p. 587] to obtain that |G p k | = p k−1 (p+1). This means that, if Φ : G p k → G p is the (mod p) group homomorphism, then |Ker Φ| = p k−1 . Finally, observe that Ker Φ is an abelian p-group with exactly p−1 elements of order p, namely {1+Bp k−1 i ∈ G p k : 1 ≤ B ≤ p−1}. Consequently it must be cyclic and the proof is complete in this case.
Proof. It is enough to consider the prime power decomposition of m and n.
In particular, if we put m = n we obtain the following.
Proof. Recall that M = n m d , where gcd(n, m d ) = 1 and we can assume, without loss of generality, that gcd(m, d) = 1. Then, Proposition 3 leads to: and the result follows.
Recall that for the classical Euler and Carmichael functions, φ(n) = λ(n) if and only if n = 2, n = 4 or n = p r , 2p r for some odd prime p and r > 0. Note that in all these cases the group (Z/nZ) ⋆ is cyclic. For our recently defined functions Φ and ⋌ we have the following: We end this section showing that the asymptotic behavior of Φ(n) is not exactly the same as that of his classical counterpart.
Proof. For the asymptotic growth of Euler φ function and its limits see [9]. Now consider sequences {S n } and {L n } given by: We have that Φ(p) = p + 1 for every odd prime p ≡ 3 (mod 4), hence since p+1 p ≥ 1+ 1/p and this series is divergent by the strong form of Dirichlet's theorem. On the other hand, where the sum in the exponent is taken over the primes p ≡ 1 (mod 4), p ≤ n. Again, by the strong form of Dirichlet's theorem, this fuction tends to 0 and result holds.

Gaussian Fermat pseudoprimes
We start this section introducing the arithmetic function F , which will play the same role as n − 1 plays in the classical setting. otherwise.
Note that, if n is prime, F (n) = |G n |.
We present the analogue to Fermat's little theorem in this gaussian setting.
Proposition 7. Let p be a prime number and let z be a gaussian integer such that p is coprime with zz. Then: Proof. Note that if z ∈ Z[i] is such that gcd(n, zz) = 1, then z/z ∈ G n . Hence, it is enough to apply Corollary 1.
Remark 1. Both conditions in Proposition 7 are equivalent.
We can consider the above result as a compositeness test for integers: if for some integer n we find a gaussian integer z such that either condition i) or ii) does not hold, then n is a composite number. Nevertheless, like in the classical setting, the converse is not always true. This fact motivates the following definition: Definition 1. A composite integer n is called a Gaussian Fermat pseudoprime (GFP) with respect to the base z ∈ Z[i] if gcd(n, zz) = 1 and condition i) (or equivalently ii)) from Proposition 7 holds for n.
In the classical setting the choice of different basis leads, in general, to different sets of associated Fermat pseudoprimes. In our case it is easy to describe a family of different basis leading to the same set of associated Gaussian Fermat pseudoprimes. Proposition 8. Let z, w be two gausian integers such that |z| = |w|. Then an integer n is a Gaussian Fermat pseudoprime with respect to z if and only if n is a Gaussian Fermat pseudoprimes with respect to w.
Proof. Assume that n is a GFP with respect to z. Then gcd(n, zz) = 1 and (z/z) F (n) ≡ 1 (mod n). Now, since |w| = |z| we have that gcd(n, ww) = gcd(n, zz) = 1. Moreover, since (z/z) F (n) ≡ 1 (mod n) and z/z ∈ G n it follows that ⋌(n) | F (n). Hence, (w/w) F (n) ≡ 1 (mod n) because w/w ∈ G n . The converse is clear since the roles of z and w are symmetric and the proof is complete.

Gaussian Carmichael and cyclic numbers
An integer n that is a Fermat pseudoprime for all bases coprime to n is called a Carmichael number [4]. In the gaussian case there also exists composite numbers which are GFP with respect all bases.
Definition 2. A composite number n ∈ N is a Gaussian Carmichael number (G−Carmichael) if it is a GFP to base z for every gaussian integer z such that n is coprime to zz.
An alternative and equivalent definition of Carmichael numbers is given by Korselt's criterion [11] which states that a positive composite integer n is a Carmichael number if and only if n is square-free, and for every prime divisor p of n, p − 1 divides n − 1. It follows from this characterization that all Carmichael numbers are odd. A similar characterization of G−Carmichael numbers can be given, showing that there are also even G−Carmichael numbers.
Proposition 9. For every composite integer n the following are equivalent.
iii) For every prime divisor p of n, F (p) divides F (n) and one of the following conditions holds: a) n is odd and square-free, b) n is multiple of 4 and n 4 = 2, 3, 5 or not a prime number. Proof. Since ⋌(n) is the exponent of the group G n , i) and ii) are clearly equivalent.
From Corollary 1 and the fact that ⋌(mn) = lcm(⋌(m), ⋌(n)) if gcd(m, n) = 1, it is easy to see that iii) implies ii) when n is a number that satisfies a) or b).
If n is odd (a = 0) and r i ≥ 2 for some i ∈ {1, . . . , s} we get that p i divides ⋌(n) and, consequently, also F (n). Thus, p i divides n − 1 or n + 1 which is a contradiction and n must be square-free in this case.
We now turn to the even case. If a = 1 and n is divisible by an other prime p such that p ≡ 1 (mod 4), then p − 1 divides F (n) = n. Hence n is a multiple of 4, a contradiction. The same follows if there exist a prime p ≡ 3 (mod 4) dividing n so we conclude that if n = 2 is even, it must be a multiple of 4. Now, let be n = 4p with p a prime. If p = 2, then n = 8 and we are done. If p ≡ 1 (mod 4), it follows that p − 1 divides n; i.e., p − 1 divides 4 so p = 5 and n = 20. Finally, if p ≡ 3 (mod 4), it follows that p + 1 divides 4 so p = 3 and n = 12. Hence we have seen that if 4 divides n and n = 8, 12, 20, then n 4 is not prime and the proof in complete.
In 1994 it was shown by Alford, Granville y Pomerance [1] that there exist infinitely many Carmichael numbers. It is easy to see that every power of 2 is a G−Carmichael number, hence there are also infinitely many of them. However, if we restrict to odd G−Carmichael numbers, the problem seems to have at least the same difficulty as the classical case.
Carmichael numbers have at least three prime factors. We know that 12 and 20 are only even G−Carmichael numbers with only two prime factors. The following result describes the family of odd G−Carmichael numbers with exactly two prime factors.
Proposition 10. Let p < q be odd primes. Then n = pq is a gaussian Carmichael number if and only if p and q are twin primes such that 8 divides p + q.
Proof. Assume that n = pq with p < q odd primes is a G−Carmichael number.
The converse is trivially true and the proof is complete.
Recall that a positive integer n which is coprime to φ(n) is called a cyclic number (sequence A003277 in [13]). This terminology comes from group theory since a number n is cyclic if and only if any group of order n is cyclic [18]. From Korselt's criterion it follows that any divisor of a Carmichael number is cyclic. In the gaussian setting we define Gaussian cyclic numbers in the following way.
The relationship between G-Carmichael and G-cyclic numbers is the same as in the setting, the proof being also quite similar.

Proposition 11. Any divisor of a odd G−Carmichael number is G−cyclic.
Proof. Let n be an odd G−Carmichael number. Since n is square-free, n = p 1 p 2 · · · p r and from proposition 2, Φ(n) = (p i − β(p i )). A divisor d of n is a product of some of these primes, that is, d = h∈J p h , J ⊆ {1, 2, . . . , r}. If GCD(Φ(d), d) <> 1,, then there exist two indices i = k in J such that p i divides p k − β(p k ). As n is a Carmichael number, we also have p k − β(p k ) divides n − β(n). Hence, p i divides n − β(n) which is absurd since n is divisible by p i and β(p i ) = ±1.
Around 1980, G. Michon conjectured that all odd cyclic numbers have Carmichael multiples. This can be reasonably extended to G−cyclic numbers and we can ask if all odd G−cyclic numbers have G−Carmichael multiples.
Cyclic numbers can also be characterized in terms on congruences. A number n is cyclic if and only if it satisfies φ(n) φ(n) ≡ 1 (mod n) or λ(n) λ(n) ≡ 1 (mod n). In our situation only one implication remains valid, namely.
Proof. Let n be a positive integer such that Φ(n) Φ(n) ≡ 1 (mod n). Then, for any prime divisor p of n it holds that Φ(n) Φ(n) ≡ 1 (mod p). Now, if n is not a G−cyclic number, there exists a prime p with p | gcd(Φ(n), n). Thus, p divides Φ(n) and Φ(n) Φ(n) ≡ 0 (mod p), a contradiction.
The converse of the previous proposition is no true. In fact there are G−cyclic numbers n that do not satisfy any of the above conditions. The first of them being :   77, 119, 133, 187, 217, 253, 287, 301, 319, 323, 341, 391, . . .

G−Lehmer's totient problem and G−Giuga's conjecture
Lehmer's totient problem, named after D. H. Lehmer, asks whether there is any composite number n such that φ(n) divides n − 1. This is true for every prime number, and Lehmer conjectured in 1932 [12] that the answer to his question was negative. He showed that if any such n exists, it must be odd, square-free, and divisible by at least seven primes. This numbers, called Lehmer numbers, are clearly Carmichael numbers and, up to date, none has been found. It is known that these numbers have at least 15 prime factors and are greater than 10 30 . Moreover, if a Lehmer number is divisible by 3, the number of prime factors increases to 40000000 with more than 360000000 digits (see [3]). We now define our analogue concept.
It is clear that every G−Lehmer number is a G−Carmichal number. Besides, it is easy to note that G−Lehmer numbers exist.
Proposition 13. Let p < q be odd primes. Then n = pq is a G−Lehmer number if and only if p and q are twin primes such that 8 divides p + q.
Note that, from Proposition 10 this result means that every odd G−Carmichael number with exactly 2 prime factors is a G−Lehmer number. Nevertheless, there are G−Lehmer numbers with more thatn 2 prime factors (A182221 in [13] In 1932, Giuga [8] proposed another conjecture about prime numbers. He postulated that a number p is prime if and only if i p−1 ≡ −1 (mod p), where the sum is taken over all integers 1 ≤ i ≤ p − 1. Giuga showed that there are no exceptions to his conjecture up to 10 1000 . This was later improved to 10 13800 [2]. A similar approach to Giugas's conjecture, replacing n − 1 by F (n), leads us to consider the following set, which contains all prime numbers.
However, this set also contains lots of composite numbers. For example, every power of 2 is in G. For odd integers we have the next result.
Proposition 14. Let be n an odd integer. If Φ(n) = F (n), then n ∈ G.
Thus, prime numbers and every known G−Lehmer numbers are in G. Furthermore, no other odd composite integer is known to be in G. So, we formulate the following conjecture regarding numbers in G.

Conjecture 1.
For every odd n, n ∈ G if and only if Φ(n) = F (n).
6. Gaussian Fermat test for numbers of the form 4k + 3.
The use of gaussian integers to perform the equivalent of Fermat's little theorem to test primality is not just a mere theoretical speculation. Lucas pseudoprimes [19] for some particular sequences can be also seen as gaussian pseudoprimes. However, Gaussian integers, and the corresponding definition of peudoprimes using powers, is more similar to the classical one than the concept of Lucas sequences.
As we have said before, we can take advantage of Proposition 7 to test primality (more precisely compositeness) of a number. This is that we call the Gaussian Fermat Test with respect to the base z. Computational evidence reveals that this test, based on the structure of G N , is very powerful when it is combined with the classical one; i.e., there are very few common pseudoprimes. Furthermore, this combination is more stronger if we restrict to numbers of the form 4k + 3. From the William Galway list [6], we have checked that every Fermat pseudoprime number to base 2 less than 10 18 and of the form 4k + 3 is not a Gaussian pseudoprime to base z = 1 + 2i.
Baillie-PSW primality test [15], used in a lot of computer algebra systems and software packages, is also a combination of two primality tests. More precisely it is a strong Fermat probable prime test to base 2 and a strong Lucas probable prime test. As the previous combination, no composite number below 10 19 passes it, but it considers two strong type-test in contrast of our two basic Fermat type tests. On the other hand, there are integers of the form 4k + 3 which are both Fermat pseudoprimes to base 2 and Lucas pseudoprimes (see sequence A227905 in [13]).
In general, combinations of two Fermat test with respect to two different prime basis (less than 30) present more than 10 (and a mean of 34) pseudoprimes lower than 4 · 10 7 of the form 4k + 3. Even if we combine two basis to test if a number n is a prime using the Gaussian Fermat Test, there are more pseudoprimes. However, there is no composite number of the form 4k + 3 less than 4 · 10 7 which is both a Gaussian pseudoprimes with respect to 1 + 2i and a Fermat pseudoprime with respect to a prime base less than 30. The lowest base to be used to find a Fermat pseudoprime with respect this base which is also a Gaussian Fermat pseudoprime to the base 1 + 2i is 10. Also with other Gaussian basis the combination with a Fermat test is very strong as it is shown in the following table, which presents the number of composite integers less than 4 · 10 7 which are simultaneously Gaussian Fermat pseudoprimes with respect to a base z (horizontal) and Fermat pseudoprimes with respect to a base a (vertical). One of the reasons explaining this phenomenon is that Carmichael numbers, which always appear when combining two classical Fermat tests, are avoided when we combine a Fermat test and a Gaussian Fermat test, because Carmichael numbers are not necessarily G−Carmichael numbers and conversely. In fact, there are no Carmichael numbers of the form 4k + 3 smaller than 10 18 which are also G−Carmichael numbers.
On the other hand, if n is a 1−Williams number, then for each prime factor p of n we have p − 1 | n − 1 and p + 1 | n + 1, so n is a Carmichael number. If n is to be a G−Carmichael it is also necessary that every factor p ≡ 1 (mod 4) satisfies p − 1 | n + 1. But, by hypothesis, n does not have this kind of factors and the result follows.
Thus, the search for a number of the form n ≡ 3 (mod 4) which is both a G−Carmichael number and a Carmichael number is harder than to find a 1−Williams number and, up to date, no 1−Williams number is known