arXiv:2011.11054v2 [math.GM] 28 Dec 2020 nt field finite hoe 1.1. Theorem 1. sequences ntefiiefield finite the in Let interval. same the over distributed udai eiusadcneuieqartcnonresidues quadratic consecutive and residues quadratic pattern itiue vrteitra [1 interval the over distributed tews,i alda called it Otherwise, R xrsini utbefrapiain eurn ml in small requiring applications for suitable is expression that nScin8 h anrslsaepoe sn e counting new a using standard proved the than are terms error results sharper 5.1. main provides It The 5.2. Lemma 8. Section in ie prime a Given Introduction 1 ety qaemodulo a lently, n atr of pattern any nti oe ute,a plcto otelatquadratic least the to application an Further, note. this in Abstract h rtepeso ssial o plctosrequiring applications for suitable is expression first The Keywords MSC2020 2020 29, December osctv udai eiusAdQartcNonresidue Quadratic And Residues Quadratic Consecutive (ii) (i) = k n N N { ≥ p u ) ( ( utemr,tenme of number the Furthermore, . ≪ 2 es udai orsde osctv udai resid quadratic Consecutive nonresidue, quadratic Least : easalitgr hsnt scnendwt h ogs r longest the with concerned is note This . small a be 1 rmr 11,Scnay11L40. Secondary 11A15, Primary : ,p k, ,p k, mod : (log F Let = ) = ) p contains p p k p p Let (o log )(log 2 2 0 : p p k k osctv udai eiusadqartcnonresidues quadratic and residues quadratic consecutive F ≥ ealrepie n let and prime, large a be p  + n ag subsets large and , p ≤ ,anneoelement nonzero a 2, 1 O ≥ − udai nonresidue quadratic p/ < u k p 2 p k p 1 osctv udai residues quadratic consecutive ,u u, hnvrteqartccongruence quadratic the whenever ). 2 ealrepie n let and prime, large a be   k ,  2 p , + 1 } 1 + nldn eo h udai eiusaeuniformly are residues quadratic The zero. including , − O u , ] ieie h udai orsde r uniformly are nonresidues quadratic the Likewise, 1].  .A Carella A. N. Modulo k 1 p ⊂ A ulshsteaypoi formulas asymptotic the has tuples 2 +  u nt field finite A . u , . . . , 1 , k F ∈ p ≪ Let . F p p log k scle a called is if if = N p e ro fteeitneof existence the of proof new A . tegers + k k ( O ( ,p k, rqartcnneiuso any or nonresidues quadratic or ues. ≥ ≥ k (log o n pattern) any (or nonresidues n integer any F − 1 1 eatlyo h ubrof number the of tally a be ) p . . k x 1 p ehiu ae nLemma on based technique otis( contains h rosaeassembled are proofs The . 2 , udai residue quadratic ) − ea nee.Te,the Then, integer. an be u ≡ ehiu,bsdon based technique, mod 0 n k n fconsecutive of uns p n h second the and , p modulo 1) + sintroduced is p ssolvable. is / squares 2 equiva- , p shows (1) Consecutive Quadratic Residues And Quadratic Nonresidues Modulo p 2

Theorem 1.2. Let p 2 be a large prime, and let k = O (log p) be an integer. Then, ≥ for any subset of consecutive elements F of cardinality p1 ε/2 # contains k A ⊂ p − ≪ A consecutive quadratic residues (or quadratic nonresidues or any pattern), ε > 0 is an arbitrary small number. Furthermore, the number of k tuples has the asymptotic formulas # 1 k 1 (i) N(k,p, )= A 1 1+ O , if k 1. A 2k − p p ≥      # (ii) N(k,p, )= A + O (k) , if k 1. A 2k ≥ Quadratic residues r F (and quadratic non residues) in finite fields have orders ord (r)= ∈ p p 2. The analysis and results for k consecutive d power residues or any pattern of d power residues have similar details, but are more complex as the orders of the elements increases. The other result consider an interesting application to the least quadratic nonresidue.

The other result considers an interesting application to the least quadratic nonresidue np modulo p. The current unconditional result for the least quadratic nonresidues in the literature states that n p1/4√e+ε, (2) p ≪ where ε> 0, and the strongest conditional result for primitive character χ states that

n (p) (log p)1.37+o(1), (3) χ ≪ see [4, Corollary 2], and Conjecture 10.1. The following result is proved here. Theorem 1.3. For any large prime p 2, the least quadratic nonresidue is bounded by ≥ n (log p)(log log p). (4) p ≪ The implied constant should be small, perhaps 20, see Table 1 in Section 12. In Section ≤ 10 several Lemmas are spliced together to prove this result. Section 3 to Section ?? cover the supporting materials and other optional topics.

2 Quadratic Symbol

Definition 2.1. Let p 2 be a prime, and let u F . The quadratic symbol modulo p of ≥ ∈ p a nonzero element u is defined by

u 1 if u is a quadratic residue; = (5) p 1 if u is not a quadratic residue.   (− In term of calculations, this can be determined via the Euler criterion

u (p 1)/2 = u − 1mod p. (6) p ≡±   Lemma 2.1. (Legendre) Let p 2 and q be a pair of distinct primes. Then, the quadratic symbol satisfies the following properties.≥

a (p 1)/2 (i) a − mod p, Euler congruence equation. p ≡   Consecutive Quadratic Residues And Quadratic Nonresidues Modulo p 3

ab a b (ii) = , completely multiplicative function. p p p     

1 (p 1)/2 (iii) − = ( 1) − , evaluation at a = 1. p − −  

2 (p2 1)/8 (iv) = ( 1) − , evaluation at a = 2. p −  

q p (p 1)(q 1)/4 (v) = ( 1) − − , . p q −    3 Some Quadratic Exponential Sums

Definition 3.1. Let p 2 be a prime. The finite Fourier transform of a periodic function ≥ f : Z C of period p is defined by −→ 1 fˆ(s)= f(t)ei2πst/p, (7) ηp√p t Fp X∈ where η =1 if p 1mod4 or η = i if p 3 mod 4. p ≡ p ≡ Except for a normalizing factor, the standard is a finite Fourier transform of the nonprincipal character χ : Z C, namely, −→ i2πts/p τs(χ)= χ(t)e . (8) t Fp X∈ Lemma 3.1. The quadratic character mod p is the unique fix point of the finite Fourier transform. Specifically s 1 t = ei2πst/p, (9) p ηp√p p   t Fp   X∈ where η = 1 if p 1mod4 or η = i if p 3mod4. p ≡ p ≡ Lemma 3.2. (Gauss) If p 2 is a prime, then ≥

2 √p if p 1mod p; ei2πu /p = ≡ (10) i√p if p 3mod p. u Fp ( X∈ ≡ Proof. It is widely available in the literature, exampli gratia, [7, Theorem 1.1.5], [15, Section 3.3], [20, Lemma 3.3]. 

Lemma 3.3. Let p 2 be a prime, and let (x p) be the quadratic character mod p. If ≥ | the element s = 0, then, 6 1 2 s ei2πu s/p = − η √p, (11) p p u Fp   X∈ where η = 1 if p 1mod4 or η = i if p 3mod4. p ≡ p ≡ Consecutive Quadratic Residues And Quadratic Nonresidues Modulo p 4

Proof. Let χ(n) = (x p). Replace the characteristic function of quadratic residue, see | Lemma 5.1, to obtain

2 ei2πu s/p = (1 + χ(u)) ei2πus/p = χ(u)ei2πus/p. (12)

u Fp u Fp u Fp X∈ X∈ X∈ The change of variable z = us returns

i2πu2s/p 1 i2πz/p 1 e = χ(s− ) χ(z)e = χ(s− )ηp√p. (13) u Fp z Fp X∈ X∈ 

Lemma 3.4. If p 2 is a prime, and a = is an integer such that gcd(a, p) = 1, then ≥ 6 a 2 ax2 + bx + c if b 4ac 0mod p; = − p − 6≡ (14) p  a (p 1) if b2 4ac 0mod p. u Fp   p X∈  − − ≡   Proof. Consult the literature, [7, Theorem 2.1.2], [17], and similar references. 

4 Some Incomplete Exponential Sums

A classical application of the finite Fourier transform provides nontrivial upper bounds of incomplete character sums. The simplest one uses the quadratic symbol or plain character χ modulo q.

Lemma 4.1. (Polya-Vinogradov) For q is a large prime, and a character χ = 1 modulo 6 q, χ(n) √q log q. (15) ≪ n x X≤ Proof. Use the finite Fourier transform of χ(n) as in Lemma 3.1 and the geometric series, and other means. 

The distribution, and various properties of the implied constant has a vast literature, and it is a topic of current research, see [5], [12], et alii. Many improved upper bounds for some specific characters such as χ( 1) = 1 or χ( 1) = 1 are known. An explicit for the − − − Burgess inequality is stated below.

Lemma 4.2. ([30]) Let p 107 be a prime, and let χ be character modulo p. Let M, and ≥ N 1 be nonnegative integer and let r 1. Then ≥ ≥ 1 1/r (r+1)/4r2 1/r χ(n) 2.7N − p (log p) . (16) ≤ M n N+M ≤ X≤ At r = 1 it reduces to the Polya-Vinogradov inequality, and as r , it becomes a trivial →∞ upper bound.

Lemma 4.3. Suppose that GRH is true. Then, for any nonprincipal character χ modulo q and any large number x, χ(n) √q log log q. (17) ≪ n x X≤ Consecutive Quadratic Residues And Quadratic Nonresidues Modulo p 5

Proof. This is done in [22, Theorem 2]. 

Lemma 4.4. (Paley) There are infinitely many discriminant q 1mod q for which ≡ n √q log log q. (18) q ≫ n x   X≤ Proof. The original version appears in [26] and a recent version is given in [21, Theorem 9.24]. 

5 Characteristic Functions For Quadratic Residues

The standard characteristic function of quadratic residues and quadratic nonresidues are induced by the quadratic symbol.

Lemma 5.1. Let p 2 be a prime, and let (x p) be the quadratic character mod p. If ≥ | u F is a nonzero element, then, ∈ p (p 1)/2 1 u 1 if u − 1mod p, (i) Ψ2 (u)= 1+ = ≡ 2 p 0 if u(p 1)/2 1mod p.     − ≡− (p 1)/2 1 u 1 if u − 1mod p, (ii) Ψ2(u)= 1 = ≡− 2 − p 0 if u(p 1)/2 1mod p,     − ≡ are the characteristic functions for quadratic residues and quadratic non residues modulo p respectively in the finite field Fp. A new representation of the characteristic function for quadratic residues and quadratic nonresidues are introduced below.

Lemma 5.2. Let p 2 be a prime, and let τ be a primitive root mod p. If u Fp is a nonzero element, then,≥ ∈

(p 1)/2 1 i2π(τ 2n u)m/p 1 if u − 1mod p, (i) Ψ2(u)= e − = (p 1)/2 ≡ p 0 if u − 1mod p. 0 n<(p 1)/2 0 m p 1  ≤ X− ≤ X≤ − ≡− (p 1)/2 1 i2π(τ 2n+1 u)m/p 1 if u − 1mod p, (ii) Ψ2(u)= e − = (p 1)/2 ≡− p 0 if u − 1mod p. 0 n<(p 1)/2 0 m p 1  ≡ ≤ X− ≤ X≤ − Proof. (i) For a fixed u = 0, the finite field F equation 6 p τ 2n u = 0 (19) − has a unique solution n = n 0, 1, 2,... (p 1)/2 1 if and only if 0 = u = τ 2n0 0 ∈ { − − } 6 is a quadratic residue modulo p. This, in turns, implies that the inner exponential sum collapses to p. Specifically,

(p 1)/2 i2π(τ 2n u)m/p p if u − 1mod p, e − = (p 1)/2 ≡ (20) 0 if u − 1mod p. 0 m p 1  ≤ X≤ − ≡− Otherwise, τ 2n u = 0, which implies that the inner exponential sum vanishes.  − 6 Consecutive Quadratic Residues And Quadratic Nonresidues Modulo p 6

6 Estimate For The Sum T (k,p)

The calculations for the sum

1 T (k,p)= 1 (21) p  0=n Fp 0 i k 1 0 ni<(p 1)/2 6 X∈ ≤Y≤ − ≤ X− assumes the existence of a sequence of k consecutive quadratic residues u, u + 1, u + 2, . . . , u + k 1 (22) − in the finite field Fp. However, it is valid for any pattern of quadratic residues and nonresidues. Lemma 6.1. Let p 2 be a large prime, let k = O (log p) be an integer, then, ≥ p 1 1 k (i) T (k,p)= − 1 , if k 1. 2k − p ≥   p (ii) T (k,p)= + O (k) , if k 1. 2k ≥ Proof. (i) Routine calculations return

1 T (k,p) = 1 (23) p  0=n Fp 0 i k 1 0 ni<(p 1)/2 6 X∈ ≤Y≤ − ≤ X− 1 p 1 k  = − p · 2 0=n Fp   6 X∈ p 1 1 k = − 1 . 2k − p   (ii) For small integer k = O (log p), the binomial series leads to p 1 1 k T (k,p) = − 1 (24) 2k − p   p 1 k 1 k 1 ( 1)k = − 1 + + + − 2k − 1 p 2 p2 · · · pk       p 1 k 1 − 1+ k ≤ 2k k/2 p p     = + O (k) , 2k since the central binomial coefficient k 2k.  k/2 ≤  7 The Estimates For The Sum U(k,p)

The exponential sums over finite fields Fp studied in Section 3 are used to estimate the sum

2n 1 i2π((τ r u ar)mr) U(k,p)=  e − −  , (25) p 0=u Fp 0 r k 1 0 nr<(p 1)/2 6 ∈ ≤ ≤ − X Y  ≤0

Lemma 7.1. Let p 2 be a large prime, let k 1 be an integer, and let τ be a primitive ≥ 2 ≥ root mod p. If the elements u + ar = vr = 0 are quadratic residues for r = 0, 1, 2, ..., k 1, then, 6 −

1 1 k (i) U(k,p)= O 1+ , if k 1. 2k p ≥   ! k (ii) U(k,p)= O , if k 1. 2k ≥   Proof. (i) Rewrite the multiple finite sum (25) as a product

2n 1 i2π((τ 0 u a0)m0) U(k,p) =  e − −  (26) p 0=u Fp 0 n0<(p 1)/2 6 X∈  ≤ X−   0

2n 1 i2π((τ r u ar)mr)  e − −  × p 1 r k 1 0 nr<(p 1)/2 ≤Y≤ −  ≤ X−   0

U(k,p) = U U (27) 1 · 2 0=u Fp 6 X∈ i2πa0/p 1 k 1 e u p + 1 − = − 1+ η2p − 4p p p · 2p 0=u Fp      6 X∈ i2πa0/p k 1 2 i2πa0/p k 1 1 e p + 1 − η e− p + 1 − u = − 1+ p − 4p 2p 4 2p p   0=u Fp   0=u Fp   6 X∈ 6 X∈ i2πa0/p k 1 e p + 1 − = − (p 1), 4p 2p −   since u 1 − = 0. (28) p 0=u Fp   6 X∈ The absolute value U(k,p) of the last expression in (27) can be rewritten as in the Lemma. | | (ii) Same as the proof in Lemma 6.1-ii. 

Lemma 7.2. Let p 2 be a large prime, and let τ be a primitive root mod p. If the ≥ element u + a = v2 = 0 is a quadratic residue, then, 0 0 6

i2πa0/p 1 2n 1 i2π((τ u a0)m) e− 2 u− U = e − − = 1+ η p , (29) 1 p 4p p p 0 n<(p 1)/2    ≤0

Proof. Rearrange the finite sum as

2n 1 i2π((τ u a0)m) U = e − − 1 p 0 n<(p 1)/2 ≤0

1 2n 2 m− 1 + 2 ei2πmτ /p = ei2πms /p = η √p. (31) p p 0 n

i2πa0/p 1 e− i2πum/p m− U = e− 1+ η √p (32) 1 4p − p p 0

k 1 2nr − 1 i2π((τ u ar)mr) p + 1 U2 =  e − −  = . (33) p 2p 1 r k 1 0 nr<(p 1)/2   ≤Y≤ −  ≤ X−   0

2n 1 i2π((τ r u ar)mr) 1 = e − − (34) p 0 nr<(p 1)/2 ≤0 mXr −p 1 ≤ ≤ − 2n 1 1 i2π((τ r u ar)mr) = 1 + e − − p p 0 nr<(p 1)/2 0 nr<(p 1)/2 ≤ X− ≤0

Solving for the incomplete exponential sum on the right side of (34) yields p + 1 p 1 = 1 − , (35) 2p − 2p which is basically the trivial value. Taking the product of all the incomplete exponential sums yields

2n 1 i2π((τ 1 u a1)m1) U2 =  e − −  p 0 n1<(p 1)/2  ≤ X−   0

1 2nk 1 i2π((τ − u ak 1)mk 1)  e − − − −  ×···× p 0 n1<(p 1)/2  ≤0

8 Consecutive Quadratic Residues And Nonresidues

Consecutive quadratic nonresidues is one of the simplest configuration of a subset of two or more consecutive quadratic nonresidues. The earliest attempts are surveyed in [13], [14], et alii. A more general result was proved by Carlitz [10, Theorem 3] using a counting technique based on Lemma 5.1. More precisely, the number of k consecutive quadratic residue symbols or any pattern of quadratic residue and quadratic nonresidue symbols

u u + 1 u + k 1 = ε0, = ǫ1, , − = ǫk 1, (37) p p · · · p −       where ǫ = 1, in the finite field F has the asymptotic formula n ± p 1 u u + 1 u + k 1 N(k,p) = 1+ ǫ0 1+ ǫ1 1+ − ǫk 1 2k p p · · · p − 0 u p 1            p ≤X≤ − = + E(k,p), (38) 2k see Lemma 5.1 for details on the the characteristic functions. An explicit error term E(k,p) = (k + 1)(3 + √p) is proved in [25, Corollary 5]. A slightly different proof ap- ± pears in a new survey [20, Theorem 5.6]. For k 2, the exponential sums involved have ≤ exact evaluations, and there are no error terms. But, in general, for k 3, with very ≥ few exceptions, the exponential sums are estimated, and have error terms of the forms E(k,p)= O(k√p). A new and sharper proof and counting technique based on Lemma 5.2 is given here.

Let a0, a1, a2, . . . , ak 1 be a sequence of distinct and increasing . Let p 2 be a − ≥ large prime, and let τ F be a primitive root. A pattern of k consecutive quadratic ∈ p Consecutive Quadratic Residues And Quadratic Nonresidues Modulo p 10

residues and quadratic nonresidues u + a0, u + a1, u + a2, . . . , u + ak 1 exists if and only if the system of equations −

2n0 2n1 2n2 2nk 1 τ = u + a0, τ = u + a1, τ = u + a2, ..., τ − = u + ak 1, (39) − has one or more solutions. A solution consists of a k-tuple n0,n1,...,nk 1 of integers such that 0 n < (p 1)/2 for i = 0, 1,...,k 1, and some u F . Let − ≤ i − − ∈ p N(k,p)=# u F : ord (u + a ) = 2 (40) { ∈ p p i } for i = 0, 1,...,k 1, denotes the number of solutions. − Proof. (Theorem 1.1): The total number of solutions is written in terms of characteristic function for quadratic residues, see Lemma 5.2, as

N(k,p) = Ψ2 (u + a0)Ψ2 (u + a1) Ψ2 (u + ak 1) (41) · · · − 0=u Fp 6 X∈

1 2ni =  ψ (τ u ai)mi)  p − − 0=u Fp 0 i k 1 0 ni (p 1)/2 6 ∈ ≤ ≤ − ≤ ≤ − X Y  0 mXi p 1   ≤ ≤ −  = T (k,p) + U(k,p). 

The term T (k,p), which is determined by the indices m0 = m1 = = mk 1 = 0, has the · · · − form 1 T (k,p)= 1 , (42) p  0=u Fp 0 i k 1 0 ni<(p 1)/2 6 X∈ ≤Y≤ − ≤ X− and the term U(k,p), which is determined by the indices m0 = 0,m1 = 0,...,mk 1 = 0, 6 6 − 6 has the form

1 2ni U(k,p)=  ψ (τ u ai)mi)  . (43) p − − 0=u Fp 0 i k 1 0 ni (p 1)/2 6 ∈ ≤ ≤ − ≤ ≤ − X Y  1 mXi p 1   ≤ ≤ −  (i) Applying Lemma 6.1-i to the termT (k,p), and Lemma 7.1-i to the termU(k,p), yield N(k,p) = T (k,p) + U(k,p) (44) p 1 1 k 1 1 k = − 1 + O 1+ 2k − p 2k p     ! p 1 k 1 = 1 1+ O 2k − p p      > 0, for all sufficiently large primes p 2. ≥ (ii) Applying Lemma 6.1-ii to the term T (k,p), and Lemma 7.1 to the term U(k,p), yield N(k,p) = T (k,p) + U(k,p) (45) p k = + O (k)+ O 2k 2k p   = + O (k) 2k > 0, for all sufficiently large primes p 2.  ≥ Consecutive Quadratic Residues And Quadratic Nonresidues Modulo p 11

9 Synopsis Of Upper Bounds For Quadratic Nonresidues

The mathematical literature has many estimates for the least quadratic nonresidue np modulo p. A list of the most frequently encountered upper bounds is complied below.

(1) n p1/2 + 1, derived using an ad hoc elementary argument, see [23, The- p ≤ orem 3.9 ], [29], etc.

(2) n p1/2 log p, derived from the Polya-Vinogradov inequality. p ≪ (3) n p1/2√e+ε, derived from the Polya-Vinogradov inequality for any ε> 0. p ≤ (4) n p1/4√e+ε, derived from the Burgess inequality for any ε> 0, see Lemma p ≤ 4.2, and [2].

(5) n pε, the Vinogradov conjecture, where ε > 0, see [16], and the p ≪ literature.

(6) n 2(log p)2, derived from the GRH, see [1], [3]. p ≤ 10 The Least Quadratic Nonresidue

Two slightly different heuristics for the conjectured upper bound of the least quadratic nonresidue are given in [24] and [30]. These are summarized below.

Conjecture 10.1. For every large prime p 3, ≥ n (log p)(log log p). (46) p ≪

The heuristic is based on the proportion of primes p such that the nth prime pn is the least quadratic nonresidue modulo p. The proportion has a geometric distribution, and its proof is based on quadratic reciprocity and Dirichlet theorem for primes in arithmetic progressions. For example, the probability for each n 1 is given by limit ≥ # p x : np = pn 1 P (np = pn) = lim { ≤ } = . (47) x n →∞ π(x) 2 Note that the form of the main term in Theorem 1.1-ii implies that quadratic residues (or quadratic non residues) in a finite field Fp are independent or nearly independent random variables X = X(p) with probability

1 1 P (ord (X)=2)= + O , (48) p 2 pε   where ε> 0 is an arbitrary small number.

On average, the expected value n of the least quadratic residue np is quite small

1 pn n = lim np = = 3.67464 ..., (49) x π(x) 2n →∞ 2

Proof. (Theorem 1.3) To obtain a reductio ad absurdum, suppose that there exists a prime p 2 for which n > (log p)(log log p). Let k = (log p)(log log p). This implies that the ≥ p finite field Fp contains a sequence of k consecutive quadratic residues u, u + 1, u + 2, . . . , u + k 1. (50) − This immediately implies that u u + 1 u + k 1 = 1, = 1, , − = 1. (51) p p · · · p       By Theorem 1.1, the total number of such sequences of quadratic residues of length k is p 1 k 1 N(k,p)= 1 1+ O 1. (52) 2k − p p ≫      Taking logarithm, and simplifying return 1 1 log p k log 2 + k log 1 + log 1+ O 0. (53) − − p p ≫      Rearranging it, and replacing k = (log p)(log log p) give k 1 log p k log 2 + O log 1+ O (54) ≫ p − p      (log p)(log log p) (log p)(log log p) log 2 + O + log C , ≫ p 0   where C 1. Clearly, this is false. Hence, a finite field F contains a quadratic non- 0 ≈ p residues n (log p)(log log p).  p ≪ The best upper bound for the parameter H 0 for which a character χ(n) modulo p ≥ is constant on the interval [N,N + H] is H < 7.07p1/4 log p for large primes, see [18, Theorem 1.1], and [31]. The above result in Theorem 1.3 provides an improved and effective upper bound H (log p)(log log p) for the parameter H 0. While the result ≪ ≥ N(k,p)= p/2k +O(k√p) in [25, Corollary 5] provides an effective lower bound H log p. ≫ Corollary 10.1. Let p 2 be a large prime, let χ be a nonprincipal character modulo p, ≥ and let x 1 be a large real number. Define the real value function ≥ f(x)= χ(n). (55) 0 n x ≤X≤ Then, f : R Z satisfies the following properties. −→ (i) f(x)= f(x + p), is periodic of period p.

(ii) f(x) p1/2 log p, is of absolute bounded variation on the real line. ≪

(iii) f(N)

(iv) f(N) >f(N + 1) > >f(N + H), is monotonically decreasing on a short in- · · · terval [N,N + H] if and only if H (log p)(log log p), for any N 0. ≪ ≥ Consecutive Quadratic Residues And Quadratic Nonresidues Modulo p 13

11 Recursive Algorithm

Let p be a prime, let np denotes the least quadratic nonresidue modulo p. The Burgess upper bound of the least quadratic nonresidue claims that

1 +ε n c p 4√e , (56) p ≤ 0 where c0 > 0, is a constant, and ε> 0 is a small number, see [4] for a survey and discussion. A recursive technique based on the Vinogradov trick for generating sharper upper bounds is introduced here. It will be demonstrated that a few iterations of the algorithm leads to the new upper bound 1 +6ε n c p 4e√e , (57) p ≤ 3 where c3 > 0 is a constant. The numerical values of the exponents of the upper bounds (56) and (57) are 1 1 (1) = 0.151632664928158 ..., (2) = 0.0557825400371075 .... 4√e 4e√e

For sufficiently large prime p, and very small ε > 0, the last 2 iterations amounts to a power saving by a factor of

1 1 +ε 6ε 0.0958501248910509 5ε p 4√e − 4e√e − = p − . (58)

Theorem 11.1. (Vinogradov trick) Let p be a prime, let x 0 is a small number, and

χ(n)= o(x), (59) n x X≤ 1 +ε then there exists n x √e such that χ(n)= 1. ≤ − A recent proof appears in [20, Theorem 2.4], and the earliest proof in [33]. The general- ization to arbitrary characters χ = 1 modulo p, and different approaches to the proofs are 6 also available in the literature. Here, this result is turned into a recursive algorithm.

Theorem 11.2. Let p be a prime, let np denotes the least quadratic nonresidue modulo p. If ε> 0 is a small number, and let χ = 1 be the quadratic character modulo p, then 6 (i) χ(n) c p1/4e√e+6ε, ≤ 2 n p X≤ 1 +6ε (ii) n c p 4e√e , p ≤ 2 where c2 > 0 is a constant. Proof. The upper bound is generated by a few iterations of the ”recursive” Vinogradov trick given below.

1/4+2ε Iteration 1. Let X0 = c0p . The standard Burgess exponential sum inequality is

1 χ(n) c p 4 +ε = o(X ), (60) ≤ 0 0 n X0 X≤ Consecutive Quadratic Residues And Quadratic Nonresidues Modulo p 14

where c0 > 0 is a constant, see [4], [20], et alii, detailed discussions. The first iteration of the Vinogradov trick yields

1 √e +ε np X0 (61) ≤ 1 1 √e +ε c p 4 +2ε ≤ 0 1  +ε1 c p 4√e , ≤ 1 where 2(1/√e + ε)ε + ε/4 = ε 3ε, and c > 0 is a constant. This is the standard 1 ≤ 1 unconditional upper bound for quadratic nonresidues in (56). This iteration is well known in the literature.

1/4√e+4ε Iteration 2. Let X1 = c1p . The corresponding exponential sum inequality is

1 +3ε χ(n) c p 4√e = o(X ). (62) ≤ 1 1 n X1 X≤ The second iteration of the Vinogradov trick yields

1 √e +ε np X1 (63) ≤ 1 1 +ε +4ε √e c p 4√e ≤ 1 1  +ε2  c p 4e , ≤ 2 where 4(1/√e + ε)ε + ε/4√e = ε 4ε, and c > 0 is a constant. 2 ≤ 2 1/4e+5ε Iteration 3. Let X2 = c2p . The corresponding exponential sum inequality is

1 +4ε χ(n) c p 4e = o(X ). (64) ≤ 2 2 n X2 X≤ The third iteration of the Vinogradov trick yields

1 +ε n X √e (65) p ≤ 2 1 +ε 1 +5ε √e c p 4e ≤ 2 1  +ε3 c p 4e√e , ≤ 3 where 5(1/√e + ε)ε + ε/4e = ε 6ε, and c > 0 is a constant.  3 ≤ 3 12 Experimental Data

The numerical data [20, Table 1], an expanded version is duplicated below, suggests that the constant is c = n /(log p)(log log p) 20 for all primes p 2. p p ≤ ≥ 13 Computational Complexity Of Quadratic Residues And Square Roots

The identification of an element u F as a quadratic residue (or quadratic nonresidue) ∈ p has nearly linear deterministic time complexity O (log p)(log log p)c) for some c> 0. The Consecutive Quadratic Residues And Quadratic Nonresidues Modulo p 15

Table 1: Numerical Data for the Least Quadratic Nonresidue Modulo p. n np = pn p (log p)(log log p) cp 1 2 3 0.10 20.00 2 3 7 1.30 2.31 3 5 23 3.58 1.40 4 7 71 6.18 1.13 5 11 311 10.03 1.10 6 13 479 11.23 1.16 7 17 1559 14.67 1.16 8 19 5711 18.66 1.02 9 23 10559 20.63 1.11 10 29 18191 22.40 1.29 11 31 31391 24.20 1.28 12 37 422231 33.18 1.22 13 41 701399 40.00 1.03 14 43 366791 32.68 1.32 15 47 3818929 41.20 1.14 discovery of an algorithm of linear complexity is an open problem, see [6, p. 3] for details.

The determination of the roots of congruence x2 u 0mod p has slightly higher time − ≡ complexity depending on the following data.

(1) The residue class of the prime p 3. ≥ (2) The method used to compute a quadratic nonresidue: probabilistic, deterministic.

(3) The method used to compute the roots: probabilistic, deterministic.

The worst case has deterministic time complexity O log p)4 bit operations. Many al- gorithms such as Cipolla algorithm, tonelli algorithm, Berlekamp algorithm etc, are ex-  plained in [6, p. 157], [11, p. 102], [9]. Some polynomials for computing the square roots are provided in [8].

14 Twin Quadratic Residues And Nonresidues

The precise numbers of pairs QQ, QN, NQ or NN of quadratic residues and quadratic nonresidues are proved in [7, Theorem 6.3.1]. The proof based on Lemma 5.2 is given below.

Theorem 14.1. Let p 3 and a Z, gcd(a, p) = 1. The number of pairs n and n + a ≥ ∈ such that (n p)= ǫ and (n p)= ǫ is exactly | 0 | 1 1 a a N(ǫ ,ǫ , P )= p 2 ǫ ǫ − ǫ ǫ , (66) 0 1 4 − − 0 p − 1 p − 0 1       where ǫ = 1. i ± Consecutive Quadratic Residues And Quadratic Nonresidues Modulo p 16

Proof. Sum the product of the two characteristic functions over the finite field Fp:

N(ǫ0,ǫ1,p) (67) 1 n n + a = 1+ ǫ 1+ ǫ 4 p 0 p 1 n Fp        n=0X∈,n= a 6 6 −

1 n n + a n2 + an = p 2+ ǫ0 + ǫ1 + ǫ0ǫ1  . 4 − p p p n Fp   n Fp   n Fp    X∈ X∈ X∈   n=0,n= a n=0,n= a n=0,n= a   6 6 − 6 6 − 6 6 −  Use Lemma 3.4 to evaluate n2 + an = 1 (68) p − n Fp   n=0X∈,n= a 6 6 − and simplify the expression. 

A new proof based on Lemma 5.2 yields the same result up to a small error term. In particular, at k = 2, Theorem 1.1 reduces to p p N(ǫ ,ǫ , P )= N(2,p)= + O (k)= + O (1) . (69) 0 1 2k 4 15 Problems

15.1 Square Roots Problems Exercise 15.1. Let n 2 be a squarefree integer, let = u = 0 : u u 1 1 mod n be ≥ U { 6 · − ≡ } the subset of units (invertible elements), and let = m2 mod n : m 0 be the subset Q { ≥ } of squares in the finite Z/nZ.

(a) Show that total number of units is # = ϕ(n)= n (1 1/p) units, where ϕ(n) U p n − is the number integers relatively to n. | Q

(b) Show that total number of squares is # = p n(p + 1)/2 squares modulo n. Q | (c) Show that a square element s = r2 Z/nZ hasQ 2ω(n) square roots modulo n, where ∈ ω(n) is the number of prime divisors of n. For example, √s = r0, r1, . . . , rm 1. − Exercise 15.2. Let n 2 be an integer, and let = m2 mod n : m 0 be the ≥ Q′ { ≥}−{ } subset of squares. Show that the subset of squares # Z/nZ is a multiplicative . Q∪ Exercise 15.3. Let n 2 be an integer, and let = m2 mod n : m 1 be the subset ≥ Q { ≥ } of squares. Find a formula for the total number of the subset of squares # . Q Exercise 15.4. Let n = pq 6, where p 2 and q 2 are distinct primes, and let ≥ ≥ ≥ m = ϕ(n) the number of units in the finite ring Z/nZ, and let = m2 mod n : m 1 Q { ≥ } be the subset of squares. Verify these questions:

(a) A square s = r2 Z/nZ has 4 = 2ω(n) square roots r , r , r , r . ∈ 0 1 2 3 (b) If p q 3 mod 4, then a single r for some i = 0, 1, 2, 3. ≡ ≡ i ∈ Q Consecutive Quadratic Residues And Quadratic Nonresidues Modulo p 17

Exercise 15.5. Let n = pq 6, where p 2 and q 2 are distinct primes, and let ≥ ≥ ≥ m = ϕ(n) the number of units in the finite ring Z/nZ, and let = k2 mod n : k 1 be Q { ≥ } the subset of squares. Verify these questions: (a) A square s = r2 Z/nZ has 4 = 2ω(n) square roots r , r , r , r . ∈ 0 1 2 3 (b) If p q 1mod4, then square roots, r for i = 0, 1, 2, 3. ≡ ≡ i 6∈ Q Exercise 15.6. Let n 2 be an integer, and let = m2 mod n : m 1 be the subset ≥ Q { ≥ } of squares. Reference: Handbook of . (a) If n = pq, where p and q are primes, and s , then the inverse s 1 s((p 1)(q 1)+1)/8 mod n. ∈ Q − ≡ − − (b) If n = pqr, , where p, q, and r are primes, and s , find a similar formula for then ∈ Q the inverse s 1 s?((p 1)(q 1)(r 1)+1)/16 mod n. − ≡ − − − 15.2 Character Sums Problems Exercise 15.7. Let q 2 be an integer, let χ be a multiplicative nonprincipal character ≥ s modulo q, and L(s,χ)= n 1 χ(n)n− . Show that ≥ P 1 c+i xs χ(n)= ∞ L(s,χ) ds, i2π s n x c i X≤ Z − ∞ where c> 1 is a constant, and x R Z is a real number. ∈ − 15.3 Sums Of Squares Problems Exercise 15.8. Let p 1mod4 be a prime, and let = k2 mod p : k 1 be the subset ≡ Q { ≥ } of squares. Show that p(p 1) r = − . 4 r X∈Q Exercise 15.9. Let n 1 be an integer, and let = k2 mod n : k 1 be the subset of ≥ Q { ≥ } squares. Classify and evaluate the sums of squares

r? . r X∈Q 15.4 Distribution And Spacing Between Squares Problems Exercise 15.10. Use the quadratic reciprocity and Dirichlet theorem for primes in arith- metic progressions to prove that the proportion of primes p such that the nth prime pn is the least quadratic nonresidue modulo p has a geometric distribution. For each n 1, ≥ the probability is given by limit

# p x : np = pn 1 P (np = pn) = lim { ≤ } = . x n →∞ π(x) 2 Exercise 15.11. Use the geometric distribution for the proportion of primes p such that the nth prime pn is the least quadratic nonresidue modulo p to compute the average least quadratic nonresidue 1 n = lim np = 3.67464 .... x π(x) →∞ 2

Exercise 15.12. Let n 2 be a squarefree integer, and let = m2 mod n : m 1 be ≥ Q { ≥ } the subset of squares. Show that the average spacing between squares

n n n2ω(n) Sn = = = , # p n(p + 1)/2 ψ(n) Q | Q where ω(n) is the prime divisors counting function, and ψ(n)/n = p n(1 + 1/p) is the Dedekind psi function, see Exercise 15.1. | Q Exercise 15.13. Let n 2 be an integer, and let = m2 mod n : m 1 be the subset ≥ Q { ≥ } of squares. Find an expression for the average spacing between squares n S = , n # Q in terms of the ω(n) is the prime divisors counting function, and σ(n)/n = pv n(1 + 1/p + 1pv) is the sum of divisors function, see Exercise 15.3. || · · · Q 15.5 Algorithm Problems Exercise 15.14. Let m,n Z be a pair of distinct integers. Construct a deterministic ∈ algorithm to compute a simultaneous quadratic nonresidue η modulo both n and m. Hint: Try a pair of distinct prime p and q first, then generalize it.

Exercise 15.15. Determine the time complexity of computing the inverse s 1 a mod p − ≡ using the . Hint: Consider Lame theorem.

1 Exercise 15.16. Determine the time complexity of computing the inverse s− a mod p p 2 ≡ using the Fermat theorem s − mod p. Hint: Consider the add-multiply algorithm.

15.6 Primitive Roots Quadratic Nonresidues Problems Exercise 15.17. Given a prime p 3, prove the followings. ≥ (a) Show that a primitive root in a finite field Fp must be a quadratic nonresidue, but a quadratic nonresidue must not be primitive root.

(b) A finite field F has (p 1)/2 ϕ(p 1) quadratic nonresidues which are not primitive p − − − roots.

(c) Verify that every quadratic nonresidues in the finite field Fp is primitive root if and n only if p = 22 + 1 is prime.

15.7 Open Problems Exercise 15.18. Given a large prime p 3, let = n2 mod p : n 1 be the subset of ≥ Q { ≥ } squares, and let , F be a pair of nonempty subsets. The subsets are proper subsets A B ⊂ p and must have zero densities in Fp to avoid trivial cases. Reference: [28], [32]. 1. (Sarkozy conjecture) Prove or disprove the existence of an additive partition = Q + . A B 2. Prove or disprove that every square is a sum of two squares: the existence of an additive partition = + , where , are a pair of nonempty proper Q A B A B ⊂ Q subsets. Consecutive Quadratic Residues And Quadratic Nonresidues Modulo p 19

3. Prove or disprove the existence of a difference partition = . Q A−B Exercise 15.19. (Lehmer conjecture) Given a large prime p 3, and let (x p) be the ≥ | quadratic symbol, and let a = r2 and b = s2 be a pair of distinct squares. Prove or disprove the claim that n + a n n + b > 1 p p p n p     X≤ exists for a finite number of primes p 2. Reference: [13, p. 246]. ≥ References

[1] Ankeny, N. C. The least quadratic non residue. Ann. of Math. (2) 55 (1952), 65-72.

[2] Burgess, D. A. A note on the distribution of residues and nonresidues. J. London Math. Soc. 38 (1963) 253-256.

[3] Bach, E. Analytic methods in the analysis and design of number theoretic algorithms, ACM Distinguished Dissertations, MIT Press, MA, 1985.

[4] Bober, J. Goldmakher, L. Polya-Vinogradov and the least quadratic nonresidue. arXiv:1311.7556.

[5] Bober, J. Goldmakher, L. Granville, A. Koukoulopoulos, D. The frequency and the structure of large character sums. J. Eur. Math. soc. 20 (2018), no. 7, 1759-1818.

[6] Bach, Eric; Shallit, Jeffrey. Algorithmic number theory. Vol. 1. Efficient algorithms. Foundations of Computing Series. MIT Press, Cambridge, MA, 1996.

[7] Berndt, Bruce C.; Evans, Ronald J.; Williams, Kenneth S. Gauss and Jacobi sums. Canadian Math. Soc. Series of Monographs. A Wiley-Interscience Publication. New York, 1998.

[8] N. A. Carella. Formulas for the Square Roots Mod p. arxiv.org/ftp/arxiv/papers/1101/1101.4605.

[9] N. A. Carella. Quadratic Nonresidues And Applications. Technical Report 190, Pace University, 2003.

[10] Carlitz, L. Sets of primitive roots. Compositio Math. 13 (1956), 65-70.

[11] Crandall, Richard; Pomerance, Carl. Prime numbers. A computational perspective. Second edition. Springer, New York, 2005.

[12] Fromm, E. Goldmakher, L. Improving the Burgess bound via Polya-Vonogradov. Proc. Amer. Math. Soc. 147 (2019), no. 2, 461-466.

[13] Guy, Richard K. Unsolved problems in number theory. Third edition. Problem Books in . Springer-Verlag, New York, 2004.

[14] Hummel, Patrick. On consecutive quadratic non-residues: a conjecture of Issai Schur. J. Number Theory 103 (2003), no. 2, 257-266. Arxiv:0305298.

[15] Lemmermyer, F. Reciprocity Laws. From Euler to Eisenstein. Springer Monographs in Mathematics. Springer-Verlag, Berlin, 2000. Consecutive Quadratic Residues And Quadratic Nonresidues Modulo p 20

[16] Linnik, Yu. A remark on the least quadratic nonresidue. C. R. (Doklady) Acad Sci. URSS (N.S) 36 (1942), 119-120.

[17] Lidl, Rudolf; Niederreiter, Harald. Finite fields. Encyclopedia of Mathematics and its Applications, 20. Cambridge University Press, Cambridge, 1997.

[18] McGown, K. On the constant in Burgess bound for the number of consecutive residues or non-residues. Arxiv.1011.4490.

[19] G. Martin and P. Pollack. The average least character non-residue and further vari- ations on a theme of Erdos, J. London Math. Soc. 87 (2013) 22-42. Arxiv.1112.1175.

[20] Kevin McGown, Enrique Trevino. The least quadratic non-residue. Preprint, July 18, 2019.

[21] Montgomery, Hugh L.; Vaughan, Robert C. Multiplicative number theory. I. Classical theory. Cambridge University Press, Cambridge, 2007.

[22] Montgomery, Hugh L.; Vaughan, Robert C. Exponetial sums with multiplicative coefficients. Invnt. Math. 43 (1977), no. 1, 69-82.

[23] Niven, I. Zuckerman,H. Montgomerry, H. An Introduction to the Theory of Numbers. Wiley & Sons, New York, 1991.

[24] Paul Pollack. The smallest quadratic nonresidue modulo a prime, Slides, August 29, 2012.

[25] Peralta, Rene. On the distribution of quadratic residues and nonresidues modulo a prime number. Math. Comp. 58 (1992), no. 197, 433-440.

[26] Paley, R. A theorem on Characters, J. London math. soc. 7 (1932), no. 1, 28-32.

[27] J.B. Rosser and L. Schoenfeld. Approximate formulas for some functions of prime numbers, Illinois J. Math. 6 (1962) 64-94.

[28] Igor E. Shparlinski. Additive Decompositions Of Of Finite Fields, arxiv.org/pdf/1301.2872.

[29] Shapiro, Harold N. Introduction to the theory of numbers. Pure and Applied Math- ematics. A Wiley-Interscience Publication. John Wiley and Sons, Inc., New York, 1983.

[30] Trevino, Enrique. The least quadratic non-residue and related problems. Slides, April 17, 2015.

[31] Trevino, Enrique. On the maximum number of consecutive integers on which the a character is constant. Mosc. J. Comb. Number Theory 2 (2012), no. 1, 56-81.

[32] Vsevolod F. Lev, Jack Sonn. Quadratic residues and difference sets, arXiv:1502.06833.

[33] I.M. Vinogradov. Sur la distribution des residus et des non-residus des puissances, Journal Physico-Math. Soc. Univ. Perm 1 (1918), 94-96.

ConsecutiveQuadraticNonresidue-12-28-20-61.tex.