Distance between consecutive elements of the multiplicative group of integers modulo n

: For a prime number p , we consider its primorial P := p # and U ( P ) := ( Z /P Z ) × the set of elements of the multiplicative group of integers modulo P which we represent as points anticlockwise on a circle of perimeter P . These points considered with wrap around modulo P are those not marked by the Eratosthenes sieve algorithm applied to all primes less than or equal to p . In this paper, we are concerned with providing formulas to count the number of gaps of a given even length D in U ( P ) which we note K ( D, P ) . This work, presented with different notations is closely related to [4]. We prove the formulas in three steps. Although only the last step relates to the problem of gaps in the Eratosthenes sieve (see section 3.2.2 page 12 ) the previous formulas may be of interest to study occurrences of defined gaps sequences.

In this paper, we are mostly concerned with providing formulas to count the number of gaps of a given even length D in U (P ) which we note K(D, P ).This work, presented with different notations is closely related to [4].We prove the formulas in three steps.Although only the last step relates to the problem of gaps in the Eratosthenes sieve (see section 3.2.2page 12 ) the previous formulas may be of interest to study occurrences of defined gaps sequences.
• For a positive integer n, we prove a general formula based on the inclusion-exclusion principle to count the number of occurrences of configurations * in any subset of Z/nZ.(see equation 7 in theorem 2.1) • For a a square-free integer P , we particularize this formula when the subset of interest is U (P ).(see equation 11 in theorem 3.2) • For a prime p and its primorial P := p#, we particularize the formula again to study gaps in U (P ).Given a positive integer D representing a distance on the circle, we give formulas to count K(D, P ) the number of gaps of length D between elements of U (P ).(see equation 15 and section 4.1) 1 Introduction

Notations
This section details some of the notations used in this paper.
• We denote the set of prime numbers by P.
• For a prime number p, we write P := p# its primorial which is the product of all prime numbers less than or equal to p.
• To facilitate reading, for an integer n we write U (n) the set of elements of the multiplicative group of Z/nZ.U (n) := (Z/nZ) × • For an integer n and a set of integers A we write A/nZ the subset of Z/nZ composed of all the elements from A taken modulo n. • For an integer n, we write S(n) and we call support the set of all its prime divisors.
S(n) = {q | q ∈ P and q | n} • With a finite set X we note P(X) the set composed of the 2 card(X) subsets of X.

Description of the problem
The objective of this section is to give a short introduction † , with some examples, of the problem that we are trying to resolve.The integer n is considered as being square-free and most of the time it will be the primorial of a given prime p.When n is not square-free the results presented here may be extended with no difficulty ‡ .
Representation In this paper, we work in Z/nZ and we represent its elements counterclockwise on a circle of circumference n.Let p = 5 and P = 5# = 30 then U (P ) = {1, 7, 11, 13, 17, 19, 23, 29} We represent the elements of U (P ) on a circle modulo P as in figure 1.We should use this example in order to illustrate the definitions to follow regarding distance and consecutiveness.Consecutiveness For any sets A and E such that A ⊂ E ⊂ Z/nZ we define a consecutiveness property consistent with the intuition: if we represent the elements of E as points marked on a circle of perimeter n (see for example the pink points in figure 1 representing E = U (30) in Z/30Z) then A, a subset of E, is deemed consecutive in E if an only if there exist an arc on the circle such that: • All the elements of A are on that arc Counting configurations Now going into the subject matter, with A ⊂ E ⊂ Z/nZ as above, we try in this paper to answer the following questions: 1. Question 1 How many rotations move A onto another subset included in E? We shall write this number ν(A, E, n).
2. Question 2 How many rotations move A onto another subset included in E that is also consecutive in E? We shall write this number κ(A, E, n).
For simplicity we can impose A to contain 0 and we shall call this a configuration.
• Answering question 1 with A = {0, 2, 4} is trying to find 3 elements in E such that there exists a rotation that moves them onto A. One finds no suitable rotation which means that ν(A, E, n) = 0.
In other words A is exactly the intersection of E and at least one interval of Z taken modulo n.
When there is no ambiguity regarding the subset E that we consider we shall say that A is a set of consecutive elements or even that A is a consecutive set.
See for instance examples 1.1 and 1.2.In the first example take for instance x = 1 and y = 12.
Regarding the second example there exists no suitable combination of x and y.
Definition 1.2 (consecutive elements).Let E be a subset of Z/nZ.We say that two distinct elements x and y in E are consecutive if and only if {x, y} is an E-consecutive set.
Definition 1.3 (gap).Let E be a subset of Z/nZ.When x and y in E are consecutive we say that they define a gap of length d(x, y).
2 General configuration counting functions

Configuration counting functions
In this section n is an integer greater than 2 and E a subset of Z/P Z.The definitions to follow are most of the time dependent on the choice of n and E or n alone.We give the definitions mentioning this explicit dependency but, in order to simplify equations, we may not always write these arguments when the context is clear, i.e. the choice of n and E is clear.
Definition 2.1 (Configuration T ).We define a configuration T as any subset of Z/nZ that contains 0.
Definition 2.2 (Configuration induced by F and x, T (F, x)).Let F be a subset of Z/nZ, any x in F defines a configuration T (F, x) with the subset T (F, x) := F − {x}.We say that the the configuration T (F, x) is the configuration induced by F and x.
Definition 2.3 (Length of a configuration L(T , n)).Let n be an integer and T a configuration of Z/nZ.We define L(T , n) the length of the configuration T as With r as defined in section 1.1.We may write L(T ) when the context is clear.
Definition 2.4 (Configuration core C(T , E, n) and its cardinal ν(T , E, n)).Let n be an integer, T a configuration of Z/nZ and E a subset of Z/nZ.We define C(T , E, n), the core of the configuration T , as the subset of Z/nZ composed of all the elements x such that for any t in T , We also define ν(T , E, n) as the cardinal of We may write C(T ) and ν(T ) when the context is clear.ν(T ) counts the number of subsets F of E such that there exists x ∈ F such that T = T (F, x).In other words it counts the number of times the configuration T can be seen in E.
Example 2.2.Let's take the example of figure 1 with n = 30.Let's take the configuration T = {0, 2, 6} and Let T be a configuration and C(T ) its core.We have Let n be an integer, E a subset of Z/nZ and T 1 and T 2 two configurations, then Definition 2.5 (Configuration consecutive core K(T , E, n) and its cardinal κ(T , E, n)).Let n be an integer, E a subset of Z/nZ, T a configuration of Z/nZ.We define K(T , E, n), the consecutive core of the configuration T , as the subset of Z/nZ composed of all the elements x such that {x} + T is E-consecutive.
We may write K(T ) or κ(T ) when the context is clear.κ(T ) counts the number of E-consecutive subsets F of E such that there exists x ∈ F such that T = T (F, x).
Proposition 2.3.Let T be a configuration, C(T ) its core and K(T ) its consecutive core.We have Let n be an integer and T a configuration of Z/nZ, we call configuration complement and we write ∆(T , P ), the subset of elements x in Z/nZ which satisfy the following two conditions, x / ∈ T and r(x) < L(T ).we may write ∆(T ) when the context is clear.
Remark 2.1.The configuration complement is not a configuration because it does not contain 0.

General consecutive core cardinal formula
Theorem 2.1 (Consecutive core cardinal formula).Let T be a configuration and ∆(T ) its complement.The following equation holds true: Proof.κ(T ) counts the number of E-consecutive sets F that contain an x such that T is the configuration induced by F and x.Also, ν(T ) counts the number of sets F ⊂ E that contain an x such that T is the configuration induced by F and x; irrespective of the consecutiveness condition.The idea of the proof is to say that κ(T ) must be equal to ν(T ) less the number of times the set F is not E-consecutive.This allows us write To calculate card δ∈∆(T ) C (T ∪ {δ}) , we use the inclusion-exclusion principle (see [1]) Then we can write Finally, coming back to the expression of κ (T ) 3 A formula when E is U (P ) for a square-free integer P In this section we consider a square-free integer P .We consider Z/P Z and its subset E := U (P ).
Let T be a configuration of Z/P Z.
Definition 3.1 (Configuration modulo a divisor).Let P be an integer and T be a configuration of Z/P Z.For any integer q that divides P , and for any t an integer modulo P of T we define t mod q as being r(t) mod q since this number modulo q is independent from the representative of t that we choose.∀k ∈ Z r(t) + kP ≡ r(t) mod q For this reason (and only because q divides P ) we can define T /qZ as if we were working with integers (see introduction).We define Then T /qZ is a configuration of Z/qZ since it is a subset of Z/qZ that contains 0.
3.1 A formula for ν(T , U (P ), P ) Theorem 3.1.Let P be a square-free integer.We consider Z/P Z and its subset E := U (P ).Let T be a configuration of Z/P Z.
Proof.let q be a prime ¶ that divides P .From 3.1 it is possible to define T /qZ a configuration of Z/qZ.Now according to the definition 2.4 for T /qZ in Z/qZ with the subset E = U (q) we have Referring to the Chinese remainder theorem (see [1]), knowing an integer (x mod q) for all its components q (all primes that divide P ) is tantamount to knowing (x mod P ).Therefore we have (x mod P ) ∈ X(P ) ⇔ ∀q ∈ S(P ) (x mod q) ∈ X(q) And therefore ν(T , U (P ), P ) = card (X(P )) = ν(T , U (q), q) = q∈S(P ) (q − card (T /qZ))

A generalization of Euler and Nagell's totient functions
Euler ϕ function Euler ϕ function is linked to ν via Nagell's totient function Nagell's totient function θ(n, P ) counts the number of solutions of the congruence n ≡ x + y mod P under the restriction (x, P ) = (y, P ) = 1 (see [3] and [2]) Proposition 3.1.Nagell's totient function can be expressed via ν through the following identity θ(n, P ) = ν({0, n} , U (P ), P ) (10) ¶ We write this prime q and not p to avoid confusions with P Proof.The expression ν({0, n} , U (P ), P ) counts the number of numbers u in Z/P Z such that u + 0 and u + n are both in U (P ).For u in C({0, n} , U (P ), P ), we write v = u + n.We have v −u = n.Say v = x and −u = y and we get to x+y = n mod P and the restriction conditions are satisfied because x is in U (P ) and is therefore coprime to P .And u in U (P ) implies y = −u is in U (P ) and therefore (y, P ) = 1.Conversly the equation x + y ≡ n mod P can be rewritten x − (−y) ≡ n mod P Because of the property u ∈ U (P ) ⇔ −u ∈ U (P ) the above equation is simply A generalized totient function With T being a configuration of Z/P Z || for an integer P we have seen that For any other T we can consider ν(T , U (P ), P ) as some sort of generalized totient function.It seems to be a generalization of another kind than those exposed in [7] 3.2 Consecutive core formula when E = U (P ) Theorem 3.2 (main formula in U (P )).Let P be a square-free integer and T a configuration of Proof.Application of theorems 2.1 and 3.1.

Another expression of formula 11
In this section we rewrite 11 using the following lemma: In addition we transform the product inside the sum into the product of two products, one for primes less than or equal to a and another one for primes strictly greater than a.

p∈S(P ) a<p
From proposition 3.2, the only terms that are non zero are those where T ∪ X ⊂ S a (the representatives in X are all even).When p > a the application of lemma 3.1 gives: The equation becomes: The term p∈S(P ) a<p (p − k − card (T )) in the inner sum does not depend on X.The equation can be rewritten: Let's write: Note that because L(T ) = 2a it is not necessary to write that c depends on a since it already depends on T .However I prefer to write it this way for readability.The equation becomes: Now, in addition to being square-free, we suppose that P is the primorial of a prime p.For a positive integer a, when we set the configuration to T = {0, 2a}.We essentially get formulas to count the number of gaps of length 2a.The gaps among numbers coprime to a primorial have been studied at length.(see for example [8] (smallest even number which is not a gap), [4] (asymptotic population of gaps) or [5] (maximum gap)) When T = {0, D} we adopt a simpler notation: K(D, P ) := κ(T , U (P ), P ) When T = {0, 2a}, we have L(T ) = 2a and card (T ) = 2.Because P = p# the equation 13 can be rewritten 4 Formulas to count the number of consecutive pairs in U (P ) 4.1 Direct application of formula 15 for D even and D ≤ 50 With a program, according to the equation 15 we calculate We have calculated the formulas for D up to 50, they are available page 18 expressed as listings.
The application of these formulas give the numbers in table 1.These numbers have been checked against an exact calculation of K(D, p#) 4.2 A property on the sum of the coefficients Proposition 4.1.If we write S the sum of the coefficients c(a, k − 2, P, T ) (see equation 12) for k ranging from 2 to a + 1 as in equation 15 and if we denote by q the greatest prime less than or equal to a (or such that 2q ≤ D) we have That means S is equal to the number of gaps of length D in U (q#). Proof.
In the examples that were given (p ≤ 29) it is interesting to note that this sum is always equal to zero.This property should not hold however for values of p ≥ 43 as indicated in the sequence A048670 from The On-Line Encyclopedia of Integer Sequences (see [6] (the Jacobsthal function applied to primorials).Indeed in U (43#), the largest gap between consecutive elements is 90 which is larger than 2 * 43 = 86.(43 is the smallest prime p such that the longest gap in U (p#) is greater than 2p) 5 Number of occurrences of gaps of length N that contain exactly i elements of U (P ) Let a be a strictly positive integer and N := 2a an even integer greater than 2 representing a gap length.In this section we consider the ν ({0, N }) pairs of elements of U (P ) that are N apart or equivalently the ν ({0, N }) gaps of length N .For i an integer satisfying 0 ≤ i < a, we provide a formula (see equation 27 in theorem 5.1) to count M (N, i) the number of occurrences of gaps of length N that contain exactly i elements of U (P ).Alternatively M (N, i) is also the number of gaps of length N that are composed of i + 1 consecutive gaps, a number that is denoted n N,i+1 in [4].
Let us introduce the following two definitions Definition 5.1 (X(N, i) and M (N, i)).Here, N is a strictly positive even integer (Say N := 2a) and i is an integer satisfying 0 ≤ i < a.Let E be the set {2, 4, . . ., 2a − 2}.We define and Lemma 5.1 (Relationship between M and X).Let a > 0 be a positive integer, N := 2a an even integer and i any integer satisfying 0 ≤ i < a.
Proof.E is the set {2, 4, . . ., 2a − 2} and card (E) = a − 1.By definition Let i be an integer such that 0 ≤ i < a and let Y be a subset of Therefore: Theorem 5.1 (Formula for M (N, i)).Let a > 0 be a positive integer, N := 2a an even integer and i any integer satisfying 0 ≤ i < a, we have the following expression to calculate M (N, i) Proof.In equation 26 from lemma 5.1, we replace X(N, i) by its definition (see equation 24).Then, we replace ν by its expression from formula 8 in theorem 3.1.

Conclusion
The paper proposes some formulas to calculate the number of occurrences of gap patterns in U (P ) based on the inclusion-exclusion principle and the Chinese Remainder Theorem.For single gaps D = 2a this happens to provide relatively simple formulas, at least from a theoretical perspective, to count the number of gaps in any U (p#) for any prime p. Unfortunately it becomes increasingly difficult to verify the formulas given the steep growth of p#.Calculating the coefficients to apply in the formulas is also very challenging since a naive calculation of K(D, P ) yields a complexity 2 a .However once the coefficients are calculated for a certain even gap D the calculation of K(D, P ) becomes possible for very large primes p.The formulas offer some perspectives to calculate K(D, P ) when it becomes impossible from a computation perspective to just count all the gaps in U (P ) due to the size of P .It may also be interesting to apply the formulas to some specific gap patterns.There are also possibilities to optimize the calculation of K(D, P ) which leads to interesting algorithmic questions and would enable the calculation of more of these values.
A Listings for formula 15 for D even and 6 ≤ D ≤ 50 We give below listings for the formulas of K(D, P ) (see section 4.1 and equation 15) for D even ranging from 6 to 50.The first value is the smallest prime number p ⋆ strictly greater than a = D 2 .The other couples indicate a coefficient c and a value b such that each couple defines the contribution c q∈P a<p ⋆ ≤q≤p (q − b) in the formula of K(D, P ).In particular, the products should be taken on primes q such that a < p ⋆ ≤ q ≤ p and therefore the formulas are only valid for p ⋆ ≤ p.

B Table of values of K(D, p#)
The values of the  A direct application of the formula gave the following numbers of occurrences of gaps in U (41#) (a list of pairs between a gap length and the number of times this gap length can be seen modulo 41#).These values satisfy DK(D, P ) = P however I couldn't validate them against an exact enumeration from U (41#).

A
/nZ := {a mod n | a ∈ A} • For an integer n and A and B two subsets of Z/nZ we note A + B := {a + b | a ∈ A and b ∈ B} A − B := {a − b | a ∈ A and b ∈ B}

Lemma 3 . 1 .Proposition 3 . 2 .Remark 3 . 1 .
Let a be a positive integer and S a = {0, 2, 4, . . ., 2a − 2, 2a} the set of all non negative even numbers less than or equal to 2a.For any prime p such that p > a and any set Y ⊂ S a we have:card (Y /pZ) = card (Y )|| Although it does not contain 0, we say that ∅ is a configuration Proof.It is enough to show that the application modulo p from S a to S a /pZ is injective.If x = y mod p then if x ̸ = y we must have |x − y| = kp with k ≥ 2 because x − y is even.(in particular k = 1 is excluded).That means |x − y| ≥ 2p > 2a which contradicts |x − y| ≤ 2a because x and y are in S a .With P = p# for some prime p and T a configuration of Z/P Z, if T contains an element whose representative is odd then ν(T , U (P ), P ) = 0 Proof.It is clear that 2 divides P .Given that T contains an element which representative is odd and given definition 3.1 which applies here we have T /2Z = {0, 1}.From theorem 3.1, ν(T , U (P ), P ) is a multiple of 2 − card (T /2Z) = 2 − 2 = 0 Because of proposition 3.2, when applying theorem 3.2 it is sufficient to only consider configurations that only contain classes with even representatives.That is because all other terms will contribute to 0 in equation 11 of theorem 3.2 .The configuration T has an even length.Say L(T ) = D = 2a.The cardinals of the sets that belong to P(∆(T )) range from 0 (for X = ∅) to a + 1 − card (T ) (for X = ∆(T )).If we split the sum over sets that have the same cardinal the equation becomes: κ(T , U (P ), P ) = a+1−card(T ) k=0 X∈P(∆(T )) card(X)=k (−1) card(X) p∈S(P ) (p − card ((T ∪ X) /pZ))

•
A and E coincide exactly on that arc (this arc does not contain an element of E which is not in A) Example 1.1.(seefigure1)ThesetA={1, 7, 11} is consecutive in E because on the arc Example 1.2.(see figure1) The set A = {1, 7, 13} is not consecutive in E. It is obvious when we look at figure1and here is a way to see this: an arc that contains A will either contain one of these three oriented arcs it contains 11, 17, 19, 23 and 29 which are in E but not in A. If this arc contains ⌢ 13, 7 it contains 17, 19, 23 and 29 which are in E but not in A. Therefore there is no arc satisfying the two conditions (to contain A and no element of E \ A) ⌢ 7, 1

Table 1 .
table below have been calculated with two different methods • Just counting the consecutive pairs in U (P ) with a program (reference calculation) • Applying formula 15 page 13 To support the validity of equation 15; it has always returned the exact number on all calculations from the table.Values of K(D, p#), D in rows, p in columns