1 Introduction

1.1 Motivation

We recall that the celebrated work of Duke, Friedlander and Iwaniec [8, 9], see also [20, 33], establishes the uniformity of distribution of fractions x(nq) /q formed by all solutions to quadratic congruence

$$\begin{aligned} x^2 \equiv n \pmod q, \qquad 1 \leqslant x \leqslant q, \end{aligned}$$
(1.1)

for a given integer n and the prime modulus q that runs up to some bound \(q \leqslant Q\). These results have had an enormous number of applications, see for example [1, 5, 6, 9, 23, 26, 30].

In [11] a somewhat dual question has been considered about the distribution of x(pq) /q for a fixed prime q when p runs over primes \(p\leqslant P\) for some parameter P, with non-trivial estimates provided that \(P \geqslant q^{2/3+ \varepsilon }\) with some fixed \(\varepsilon > 0\).

Here we consider a combined scenario of congruences \(x^2 \equiv p \pmod q\) when p varies over primes \(p \leqslant P\) and q varies over integers \(q \leqslant Q\).

More precisely, given a prime q and a real parameter P we consider the set \(\mathcal {N}_q(P)\) of primes \(p \leqslant P\) which are quadratic residues modulo q. Following [11], we are interested in the distribution of solutions to the congruence

$$\begin{aligned} x^2 \equiv p \pmod q, \qquad p \in \mathcal {N}_q(P) . \end{aligned}$$

Obviously to be able to answer this question one needs good lower bounds on the abundance of primes in \(\mathcal {N}_q(P)\), that is, on the cardinality

$$\begin{aligned} N_q(P) = \# \mathcal {N}_q(P). \end{aligned}$$

Unfortunately, unless P is exponentially large, all known results of this type are conditional on the Generalised Riemann Hypothesis or other conjectures on the zero-free regions of L-functions, see [11].

Here we show that a result of [11] on square roots of primes in residue rings modulo q can be improved on average over q and can also be given in a fully unconditional form. This is based on two ingredients:

  • an asymptotic formula for \(N_q(P)\) on average over q which follows from a large sieve-type result of Heath-Brown [17] on average values of sums of real characters;

  • a new bound of bilinear sums with modular square roots of integers from [32] which we couple with the Heath-Brown identity (see [21, Proposition 13.3]) to estimate exponential sums with square roots of primes.

As we have noticed, our result is an unconditional averaged version of a result from [11] with averaging over the modulus q. It can also be viewed as an averaged version of results of Duke, Friedlander and Iwaniec [8, 9], Homma [20] and Toth [33], to the scenario when n in (1.1) varies over primes \(p \leqslant P\).

Finally, we mention that the results and methods of [24, 25] undoubtedly lead to a uniformity of distribution result for solutions to

$$\begin{aligned} x^2 \equiv p \pmod {q^k}, \qquad p \in \mathcal {N}_q(P), \end{aligned}$$
(1.2)

with a fixed odd prime q as \(k\rightarrow \infty \), starting with very short intervals, namely, already for \(P\geqslant q^{\varepsilon k}\) with any fixed \(\varepsilon > 0\) (clearly \(p \in \mathcal {N}_q(P)\) is equivalent to the solvability of (1.2)).

1.2 New result

More precisely, given \(\lambda \in \mathbb {Z}_q^\times \), where \(\mathbb {Z}_q^{\times }\) is the unit group of the residue ring \(\mathbb {Z}_q\) modulo q, we define

$$\begin{aligned} \Delta _{\lambda , q} (P) = \max _{[Y+1, Y+X]\in [1, q-1]} \left| T_{\lambda , q}(P;X,Y) - 2 \frac{X}{q} N_{\lambda , q}(P)\right| , \end{aligned}$$

where a \(T_{\lambda , q}(P;X,Y)\) denotes the number of \(x \in [Y+1, Y+X]\) with \(x^2 \equiv \lambda p \pmod q\) for some prime \(p \leqslant P\) and \(N_{\lambda , q}(P)\) is the number of primes \(p\leqslant P\) such that \(\lambda p\) is a quadratic residue modulo q.

In particular, for any integer \(\lambda \ne 0\) with \(\gcd (\lambda ,q) =1\) we have either \(N_{\lambda , q}(P) = N_q(P)\) or \(N_{\lambda , q}(P) = \pi (P) - N_q(P)\) is the number of primes \(p\leqslant P\), which are quadratic residues modulo q, where, as usual, \(\pi (P)\) denotes the number of primes \(p \leqslant P\).

We certainly expect that \(N_{\lambda , q}(P)\) is about \(0.5 \pi (P)\), which in fact is known on average over q, see also Lemma 3.2 below for a precise statement.

Furthermore, it may also make sense to define a slightly different discrepancy which does not appeal to the quantity \(N_{\lambda , q}(P)\). Namely we set,

$$\begin{aligned} \widetilde{\Delta }_{\lambda , q} (P) = \max _{[Y+1, Y+X]\in [1, q-1]} \left| T_{\lambda , q}(P;X,Y) - \frac{X}{q} \pi (P) \right| . \end{aligned}$$

In [11] the discrepancy \(\widetilde{\Delta }_{\lambda , q}(P)\) is estimated under the condition that for the given prime q, the number of prime quadratic residues \(p \leqslant P\) is close to its expected value \(0.5 \pi (P)\). Here we take advantage of averaging over \(q~\text {prime}\) and obtain an unconditional result with a stronger bound on average.

Theorem 1.1

Let \(1\leqslant P \leqslant Q\) and let \(\Gamma _{\lambda , q}(P)\) be either \(\Delta _{\lambda , q}(P)\) or \(\widetilde{\Delta }_{\lambda , q}(P)\) Then we have

$$\begin{aligned} \frac{1}{Q} \sum _{\begin{array}{c} q \leqslant Q\\ q~\text {prime} \end{array}} \max _{\lambda \in \mathbb {Z}_q^\times } \Gamma _{\lambda , q}(P) \leqslant P \left( P^{-1/12} + P^{-1/5} Q^{1/10}\right) Q^{o(1)} . \end{aligned}$$

It is easy to see that Theorem 1.1 is nontrivial for \(P \geqslant Q^{1/2+ \varepsilon }\) with some fixed \(\varepsilon > 0\), while for almost all primes q with \(q\geqslant P \geqslant q/2\) we get \(\Delta _{\lambda , q} (P) \leqslant P^{11/12 + o(1)}\), uniformly over \(\lambda \in \mathbb {Z}_q^\times \).

Perhaps considering more cases in the proof of Theorem 1.1 one can obtain a improve the bound of Theorem 1.1. However our goal has been to have a nontrivial result in a range of P as wide as possible and we believe that the above condition \(P \geqslant Q^{1/2+ \varepsilon }\) is the limit of our method.

Clearly, using Theorem 1.1 one can provide averaged versions of many applications which rely on the bound of Duke, Friedlander and Iwaniec [9, Theorem 1.1]; some of them are indicated already in [9], some other can be found in [1, 6, 23, 26].

2 Links to other problems

2.1 Local spacings

The local spacing distribution of the sequence \(n^2 \alpha \) mod 1 for \(\alpha \) irrational has been extensively studied in the literature. A classical result of Rudnick and Sarnak [28] states that for all integers \(d \geqslant 2\) and almost all real \(\alpha \), the pair correlation of the sequence \(n^d \alpha \) mod 1 is Poissonian. This is in contrast with the case \(d = 1\), where it is well known that for all \(\alpha \) and all N, the gaps between consecutive elements of fractional parts \(\{n\alpha \}\), \(1 \leqslant n \leqslant N\), can take at most three values. Returning to the case \(d = 2\), Rudnick, Sarnak and Zaharescu [29, 35] have shown that for sufficiently well approximable numbers \(\alpha \), the m-level correlations and consecutive spacings are Poissonian along subsequences. For \(\alpha = \sqrt{2}\), these types of conjectures are supported numerically [16] because of their close connection to the distribution between neighbouring levels of a certain integrable quantum system.

A difficult problem is that of the distribution of local spacings between consecutive primes. Gallagher [14] proves that the sequence of primes has a Poissonian distribution, conditionally under the assumption of (a uniform version of) an even more famous conjecture, the prime k-tuple conjecture.

Let us now take a large prime number q and consider two sequences modulo q: the sequence of primes up to q, and the sequence of squares of positive integers up to N. Suppose N is of the size of \(q/\log q\), so that the above two finite sequences have about the same number of elements. By Gallagher’s result [14], the first sequence has a Poissonian distribution, conditionally under the prime k-tuple conjecture. Unconditionally, by [29], the second sequence has a Poissonian distribution for N of the above size. Under these circumstances one would naturally expect that if one takes the union of these two sequences, the new sequence has a Poissonian distribution, too. Thus, for example, the nearest-neighbour distribution should be exponential: for each fixed \(\lambda > 0\), the proportion of gaps between consecutive elements of the sequence (arranged increasingly in the interval [1, q]) should tend to \(e^{-\lambda }\), as q tends to infinity. Note that the distribution problem for this combined sequence introduces new challenges. Thus, if one wants to count neighbours (pairs of consecutive elements of the sequence) asymptotically, one needs to deal with four types of pairs: pairs where both elements are primes (counted in [14]), pairs where both elements are squares mod q (counted in [29]), as well as new types of pairs, where one element is a prime and the other is a square. Counting these new types of pairs leads one to study the problem of finding, for each fixed integer h, an asymptotic formula for the number of solutions to the congruence \(n^2 \equiv p + h\) (mod q). Here the case \(h = 0\) would need to be included, too, and in that case the problem reduces to the congruence discussed in the present paper.

2.2 Diophantine inequalities

Diophantine inequalities with primes and respectively with squares have a long history. In the case of primes, Matomäki [27] proved that for any real irrational number \(\alpha \), and any \(\varepsilon > 0\), there are infinitely many prime numbers p for which

$$\begin{aligned} \Vert p\alpha \Vert <\frac{1}{p^{1/3 - \varepsilon }} . \end{aligned}$$

where \(\Vert \xi \Vert \) denotes the distance between \(\xi \) and the closest integer.

In the case of squares, it is shown in [34] that for any real irrational number \(\alpha \) and any \(\varepsilon > 0\), there are infinitely many positive integers n for which

$$\begin{aligned} \Vert n^2\alpha \Vert <\frac{1}{n^{2/3 - \varepsilon }} . \end{aligned}$$

The following question naturally arises: Given a real irrational number \(\alpha \) and positive integers P and N, can one find a prime \(p \leqslant P\) and a positive integer \(n \leqslant N\) such that \(p\alpha \) and \(n^2\alpha \) are close to each other modulo 1?

Here one may expect that since n can take N values and p can take about \(P/\log P\) values, there should be a pair (pn) for which the distance between the fractional part of \(p\alpha \) and the fractional part of \(n^2\alpha \) is less than \(1/(PN)^{1-\varepsilon }\). Such an expectation is simply false.

Indeed, consider for instance the case \(P = N^2\). Then all the differences \(p - n^2\) that can appear are nonzero integers in the interval \([-P, P]\). Recall that Dirichlet’s theorem is best possible: almost all real numbers have Diophantine type exactly 2. For such an \(\alpha \), one cannot find nonzero integers m in the interval \([-P, P]\) for which \(\Vert m\alpha \Vert < 1/P^{1+\varepsilon }\), and therefore one cannot find a pair (pn) as above for which the distance between the fractional part of \(p\alpha \) and the fractional part of \(n^2\alpha \) is less than \(1/P^{1+\varepsilon }\).

We remark that for the same real numbers \(\alpha \), (that is, of Diophantine type equal to 2) one can combine [27] with [34] to conclude that for infinitely many \(P = N^2\) as above, there exist pairs (pn) for which

$$\begin{aligned} \Vert p\alpha - n^2\alpha \Vert < 1/P^{1/3-\varepsilon }. \end{aligned}$$

To obtain the result one actually makes both \(\Vert p\alpha \Vert \) and \(\Vert n^2\alpha \Vert \) smaller than \(1/P^{1/3-\varepsilon }.\) This applies in particular to the case when the given real irrational number \(\alpha \) is algebraic, by the Thue–Siegel–Roth theorem.

Let us remark that the above type of questions have connections with some celebrated unsolved problems involving primes and squares. For example, a well known conjecture of Hardy and Littlewood states that every large enough positive integer is either a square, or the sum of a prime and a square. Assuming this holds true, and applying it to m above (or applying it to 2m in case m is a square), it follows that there is a pair (pn) such that the fractional part of \(p\alpha \) and the fractional part of \(n^2\alpha \) are either both O(1/P), or both are \(1 - O(1/P)\), or they are at distance O(1/P) from being symmetrically placed with respect to 1/2.

Another well known conjecture of Hardy and Littlewood states that any large enough odd number is the sum of a prime and 2 times a square. Assuming this conjecture holds true, and applying it to \(2m+1\) in a similar way as above, it follows that there is a pair (pn) such that \(p\alpha \) and \(2n^2\alpha \) are at distance O(1/P) from being symmetrically placed with respect to \(\alpha /2\) modulo 1. Less famous than the celebrated Goldbach conjecture, this conjecture actually goes back to Goldbach, too. He stated the conjecture in a letter to Euler dated 18 November 1752. For more on the history of this problem, the reader is referred to Hodges [19].

Suppose now that \(\alpha \) has a higher Diophantine type, and let b/q be a rational number such that

$$\begin{aligned} \left| \alpha - \frac{b}{q}\right| < \frac{1}{q^K}. \end{aligned}$$
(2.1)

Assume \(K > 3\). Also, assume that both P and N are smaller than q, and do not necessarily satisfy \(P = N^2\). Now if one tries to find a prime p up to P and a positive integer n up to N such that \(p\alpha \) is close to \(n^2\alpha \) modulo 1, then one is actually forced to restrict themselves to only consider pairs (pn) for which \(n^2 \equiv p \pmod q\). Indeed, for any other pair (pn) the numbers bp and \(bn^2\) are incongruent modulo q, so pb/q and \(n^2b/q\) differ by at least 1/q. On the other hand

$$\begin{aligned} |p\alpha - pb/q|< P/ q^K < 1/q^{K-1} \end{aligned}$$

and similarly

$$\begin{aligned} |n^2\alpha - n^2b/q|< N^2/q^K < 1/q^{K-2}. \end{aligned}$$

With \(K > 3\), both the above quantities are much smaller than 1/q. Thus

$$\begin{aligned} \Vert p\alpha - n^2\alpha \Vert \geqslant 1/q + O\left( q^{-K+2}\right) . \end{aligned}$$

By contrast, each pair (pn) for which \(n^2 \equiv p \pmod q\) automatically produces a better result:

$$\begin{aligned} \Vert p\alpha - n^2\alpha \Vert = O\left( (P+N^2)/q^K\right) . \end{aligned}$$

We end this section with the following remark. Notice that one may be able to improve on this bound by studying the distribution of square roots of primes p up to P modulo q. This is directly related to the topic of the present paper. Indeed, a strong bound on the discrepancy of such a set of square roots would imply the existence of such square roots in reasonably short intervals. In particular, it would imply the existence of numbers \(n \leqslant N\), with N reasonably smaller than q, with \(n^2\) congruent mod q to a prime less than P. This is achieved in Theorem 1.1 above, not for every q, but for most primes q up to Q. There is however no principal obstacle to extending this result to averaging over all integers \(q \leqslant Q\).

Remark 2.1

Using standard tools of the theory of Diophantine approximations, see [31, Theorem 1], it is easy to show that for any \(K>0\), for a set of \(\alpha \in [0,1]\) of Hausdorff dimension 2/K, there are infinitely many approximations (2.1) with primes q from a set of asymptotic density one.

3 Preliminaries

3.1 Notation

Throughout the paper, the notation \(U = O(V)\), \(U \ll V\) and \( V\gg U\) are equivalent to \(|U|\leqslant c V\) for some positive constant c, which throughout the paper may depend on a small real positive parameter \(\varepsilon \).

For any quantity \(V> 1\) we write \(U = V^{o(1)}\) (as \(V \rightarrow \infty \)) to indicate a function of V which satisfies \(|U| \leqslant V^{\varepsilon }\) for any \(\varepsilon > 0\), provided V is large enough.

For a real \(A> 0\), we write \(a \sim A\) to indicate that a is in the dyadic interval \(A \leqslant a < 2A\).

For \(\xi \in \mathbb {R}\) and \(m \in \mathbb {N}\) we denote

$$\begin{aligned} \textbf{e}(\xi )=\exp (2 \pi i \xi ) \qquad \text{ and }\qquad {\mathbf {\,e}}_m(\xi ) = \exp (2 \pi i \xi /m) . \end{aligned}$$

We also use (k/q) to denote the Jacobi symbol of k modulo an odd integer \(q\geqslant 2\).

We always use the letter p, with or without subscript, to denote a prime number.

As usual, for an integer a with \(\gcd (a,q)=1\) we define \(\overline{a}\) by the conditions

$$\begin{aligned} a \overline{a} \equiv 1 \pmod q \qquad \text{ and }\qquad \overline{a} \in \{1, \ldots , q-1\} . \end{aligned}$$

We also use \(\textbf{1}_{\mathcal {S}}\) to denote the characteristic function of a set \(\mathcal {S}\) and denote by \(|\mathcal {S}|\) the cardinality of this set. Finally, we recall that

$$\begin{aligned} \mathop {{\mathop {\sum }\nolimits ^*}}\limits \qquad \text{ and }\qquad \mathop {{\mathop {\sum }\nolimits ^\sharp }}\limits \end{aligned}$$

mean that the summation is over integers, which are coprime to q and over odd integers, respectively.

3.2 Bilinear forms and equidistribution

Given \(a,h \in \mathbb {Z}_q^{\times }\), integer numbers \(M,N\geqslant 1\) and complex weights

$$\begin{aligned} \varvec{\alpha }= (\alpha _m)_{m=1}^M \quad \text {and} \quad \varvec{\beta }= (\beta _n)_{n=1}^N , \end{aligned}$$

we consider bilinear forms in Weyl sums for square roots

$$\begin{aligned} W_{a,q}(\varvec{\alpha }, \varvec{\beta }; h,M,N) = \mathop {{\mathop {\sum }\nolimits ^*}}\limits _{m=1}^M \mathop {{\mathop {\sum }\nolimits ^*}}\limits _{n=1}^N \alpha _{m} \beta _{n} \sum _{\begin{array}{c} x \in \mathbb {Z}_q \\ x^2 = amn \end{array}} {\mathbf {\,e}}_q(hx) , \end{aligned}$$
(3.1)

where, as mentioned above, \(\sum ^*\) means that the summation is over integers which are coprime to q. We also remark that the equation \(x^2 = amn\) in the definition of the sums (3.1) is considered in \(\mathbb {Z}_q\) and thus is equivalent to the congruence \(x^2 \equiv amn \pmod q\).

The goal is to improve the trivial bound

$$\begin{aligned} W_{a,q}(\varvec{\alpha }, \varvec{\beta }; h,M,N) = O\left( \mathop {{\mathop {\sum }\nolimits ^*}}\limits _{m=1}^M |\alpha _{m} | \mathop {{\mathop {\sum }\nolimits ^*}}\limits _{n=1}^N |\beta _{n}| \right) . \end{aligned}$$

For many applications this is especially important to achieve below the so-called Pólya–Vinogradov range, that is, for \(M,N \leqslant q^{1/2}\), since as it has been shown by Dunn and Zaharescu [10] this leads to a power saving in the error term of an asymptotic formula for a second moment of certain L-functions.

For prime q, first nontrivial bounds on the sums (3.1) have been given in [10] and then improved in [11, Theorem 1.7]. Furthermore, in [32] the bounds of [11, Theorem 1.7] have been improved on average over q where the averaging involves all odd integers q rather than only primes.

Although the result of [32] (and also of [11]) are more general, to simplify the exposition we assume that the weights \(\varvec{\alpha }\) and \(\varvec{\beta }\) satisfy

$$\begin{aligned} |\alpha _m| \leqslant m^{o(1)} \qquad \text{ and }\qquad | \beta _n | \leqslant n^{o(1)} . \end{aligned}$$
(3.2)

Recall that for real positive Q we write \(q \sim Q\) to indicate \(q \in [Q, 2Q)\). It is convenient to define

$$\begin{aligned} \begin{aligned} {\mathfrak B}(M,N,Q)&= (MN)^{3/4} Q^{1/8} \left( M^{1/4} Q^{-1/8} + 1\right) \\&\quad \left( N^{1/4} Q^{-1/8} + 1\right) , \end{aligned} \end{aligned}$$
(3.3)

which is the bound of [32] on the sums \(W_{a,q}(\varvec{\alpha }, \varvec{\beta }; h,M,N)\) on average.

More precisely, we now consider the average value

$$\begin{aligned} {\mathfrak A}(Q)&= \frac{1}{Q} \mathop {{\mathop {\sum }\nolimits ^\sharp }}\limits _{q \sim Q} \max _{1\leqslant M,N \leqslant Q} \ \max _{a,h \in \mathbb {Z}_q^{\times }}\\ {}&\quad \max _{\varvec{\alpha }, \varvec{\beta }\ \text {as in~(3.2)}} \left( \frac{ \left| W_{a,q}(\varvec{\alpha }, \varvec{\beta }; h,M,N)\right| }{{\mathfrak B}(M,N,Q)} \right) ^4 \,, \end{aligned}$$

where, as before, \(\sum ^\sharp \) means that the summation is over odd integers.

By [32, Theorem 2.1], we have

Lemma 3.1

For \(Q \rightarrow \infty \), we have

$$\begin{aligned} {\mathfrak A}(Q)= Q^{o(1)} . \end{aligned}$$

In particular, if \(M, N \leqslant Q^{1/2}\) then the bound \({\mathfrak B}(M,N,Q)\) in (3.3) takes form

$$\begin{aligned} {\mathfrak B}(M,N,Q) \asymp (MN)^{3/4} Q^{1/8} . \end{aligned}$$

where \(A\asymp B\) means \(A \ll B \ll A\). The bound in Lemma 3.1 is better than the trivial bound provided that \(MN \geqslant Q^{1/2+\varepsilon }\), for some fixed \(\varepsilon > 0\), while the bounds of [11]

require \(MN \geqslant Q^{3/5+\varepsilon }\) and \(MN \geqslant Q^{2/3+\varepsilon }\), respectively.

3.3 Distribution of prime quadratic residues on average

We use the following immediate implication of a result of Heath-Brown [17] on the overage values of sums of real characters.

Let as before \(N_q(P)\) be the number of primes \(p\leqslant P\), which are quadratic residues modulo q.

Lemma 3.2

Let \(1\leqslant R \leqslant Q\). Then, for any integer \(\lambda \ne 0\), we have

$$\begin{aligned} \frac{1}{Q} \sum _{\begin{array}{c} q \leqslant Q\\ q~\textrm{prime} \end{array}} \max _{P \leqslant R} \left| N_{\lambda ,q}(P) - \frac{1}{2} \pi (P)\right| \leqslant R^{1/2} Q^{o(1)} . \end{aligned}$$

Proof

Clearly, for \(q\not \mid \lambda \), we have

$$\begin{aligned} N_{\lambda ,q}(P) = \frac{1}{2} \sum _{p \leqslant P}\ \left( \left( \frac{p}{q}\right) +1\right) . \end{aligned}$$

Hence

$$\begin{aligned} \sum _{\begin{array}{c} q \leqslant Q\\ q~\text {prime} \end{array}} \left| N_{\lambda ,q}(P)- \frac{1}{2} \pi (P)\right| \leqslant \sum _{q \leqslant Q} \left| \sum _{p \leqslant P}\left( \frac{p}{q}\right) \right| +O(1) . \end{aligned}$$
(3.4)

Using the standard completing technique, see [21, Section 12.2],

$$\begin{aligned} \max _{P\leqslant R} \left| \sum _{p \leqslant P}\left( \frac{p}{q}\right) \right| \ll \sum _{r=-R}^R \frac{1}{|r| + 1} \left| \sum _{p \leqslant R}\left( \frac{p}{q}\right) \textbf{e}_R(r p)\right| . \end{aligned}$$

On the other hand, a very special case of [17, Theorem 1] implies

$$\begin{aligned} \sum _{\begin{array}{c} q \leqslant Q\\ q~\text {prime} \end{array}} \ \left| \sum _{p \leqslant R}\left( \frac{p}{q}\right) \textbf{e}_R(r p)\right| ^2 \leqslant R Q^{1+o(1)} . \end{aligned}$$
(3.5)

Using the Cauchy inequality, we see that (3.4) and (3.5) imply the desired result.

In particular, we see from Lemma 3.2 that for all but \(Q^{1+o(1)}R^{-1/2} \) primes \(q \sim Q\), we have

$$\begin{aligned} N_{\lambda ,q}(P) =\left( \frac{1}{2}+o(1)\right) \pi (P). \end{aligned}$$

3.4 Exponential sums and discrepancy

We recall that the discrepancy \(D_N\) of a sequence \(\xi _1, \ldots , \xi _N \in [0,1)\) is defined as

$$\begin{aligned} D_N = \frac{1}{N}\sup _{0\leqslant \gamma \leqslant 1} \left| \#\{1\leqslant n\leqslant N:~\xi _n\in [0, \gamma )\} - \gamma N \right| . \end{aligned}$$
(3.6)

We remark that this notion of discrepancy is normalized by the presence of the factor 1/N. One may also work with the unnormalized discrepancy, where the factor 1/N is missing from the right side of (3.6). Thus the normalized discrepancy is bounded by 1, the unnormalized discrepancy is bounded by N, and the connection between them is simply that the unnormalized discrepancy equals N times the normalized discrepancy.

We now recall the classical Erdős–Turán inequality, which links the discrepancy and exponential sums (see, for instance, [7, Theorem 1.21] or [22, Theorem 2.5]).

Lemma 3.3

Let \(\xi _n\), \(n\in \mathbb {N}\), be a sequence in [0, 1). Then for any \(H\in \mathbb {N}\), the discrepancy \(D_N\) given by (3.6) satisfies

$$\begin{aligned} D_N \leqslant 3 \left( \frac{1}{H+1} + \frac{1}{N}\sum _{h=1}^{H}\frac{1}{h} \left| \sum _{n=1}^{N} \textbf{e}(h\xi _n) \right| \right) . \end{aligned}$$

It is now useful to recall the definition of the Gauss sum

$$\begin{aligned} \mathcal {G}_q(a,b,q)= \sum _{x \in \mathbb {Z}_q} \textbf{e}_q \left( ax^2+bx \right) , \qquad (a,b) \in \mathbb {Z}_q^\times \times \mathbb {Z}_q . \end{aligned}$$

The standard evaluation [21, Theorem 3.3], for odd integer modulus \(q \geqslant 3\) leads to the formula

$$\begin{aligned} \mathcal {G}_q(a,b)=\textbf{e}_q \left( -\overline{4a} b^2 \right) \varepsilon _{q} \sqrt{q} \left( \frac{a}{q} \right) , \end{aligned}$$
(3.7)

where

$$\begin{aligned} \varepsilon _{q} ={\left\{ \begin{array}{ll} 1 \quad &{} \text {if } q\equiv 1 \pmod 4,\\ i \quad &{} \text {if } q\equiv -1 \pmod 4 . \end{array}\right. } \end{aligned}$$

We also need the following bound for exponential sums over square roots modulo primes. Since below q is always prime, we use the notation of the finite field \(\mathbb {F}_q\) of q elements instead of \(\mathbb {Z}_q\).

Lemma 3.4

For a prime q, an integer \(W \leqslant q\) and integers a and h with \(\gcd (ah,q)=1\), we have

$$\begin{aligned} \sum _{w = 1}^W \sum _{\begin{array}{c} x \in \mathbb {F}_q\\ x^2\equiv a w \pmod q \end{array}} \textbf{e}_q(hx) \ll q^{1/2+o(1)}. \end{aligned}$$

Proof

Completing the exponential sum as in [21, Section 12.2] gives that

$$\begin{aligned} \sum _{w = 1}^W \sum _{\begin{array}{c} x \in \mathbb {F}_q\\ x^2\equiv a w \pmod q \end{array}}\textbf{e}_q(hx) \ll \max _{0 \leqslant t \leqslant q-1} \left| \mathcal {G}_q(t \overline{a},h) \right| \cdot \log q . \end{aligned}$$

Since \(\gcd (h,q) =1\), the value \(t=0\) does not contribute anything and for any \(t \in \mathbb {F}_q^\times \) we use (3.7).

4 Proof of Theorem 1.1

4.1 Preliminary discussion

We follow closely the approach of [11], however our estimates are slightly different, so we present the proof in full detail. We recall that in Theorem 1.1 the modulus q runs through primes. Hence we use \(\mathbb {F}_q\) instead of \(\mathbb {Z}_q\).

As in [11], we see that Lemma 3.3 reduces the discrepancy question to estimating the exponential sum

$$\begin{aligned} S_{\lambda , q}(h,P)= \sum _{p\leqslant P} \sum _{\begin{array}{c} x \in \mathbb {F}_q\\ x^2 \equiv \lambda p\pmod q \end{array}} {\mathbf {\,e}}_q(hx). \end{aligned}$$

Thus our goal is to estimate

$$\begin{aligned} {\mathfrak S}(P,Q) = \sum _{\begin{array}{c} q \sim Q\\ q~\text {prime} \end{array}} \max _{h \in \mathbb {F}_q^\times } \left| S_{\lambda , q}(h,P)\right| . \end{aligned}$$

In turn, using partial summation, one can bound the sums \({\mathfrak S}(P,Q)\) via the sums

$$\begin{aligned} \widetilde{{\mathfrak S}}(P,Q) = \sum _{\begin{array}{c} q \sim Q\\ q~\text {prime} \end{array}} \max _{T \leqslant P} \max _{h \in \mathbb {F}_q^\times } \max _{\lambda \in \mathbb {F}_q^\times } \left| \widetilde{S}_{\lambda , q}(h,T)\right| , \end{aligned}$$
(4.1)

where

$$\begin{aligned} \widetilde{S}_{\lambda , q}(h,T) = \sum _{k=1}^T \Lambda (k) \sum _{\begin{array}{c} x \in \mathbb {F}_q\\ x^2 \equiv \lambda k\pmod q \end{array}} {\mathbf {\,e}}_q(hx) \end{aligned}$$

and, as usual, we use

$$\begin{aligned} \Lambda (n) = {\left\{ \begin{array}{ll} \log p&{}\quad \text {if}\,n\hbox { is a power of the prime }p,\\ 0 &{}\quad \text {otherwise}, \end{array}\right. } \end{aligned}$$

to denote the von Mangoldt function.

Thus our goal is to estimate \(\widetilde{{\mathfrak S}}(P,Q)\) and prove the upper bound

$$\begin{aligned} \widetilde{{\mathfrak S}}(P,Q) \leqslant \left( R^{11/12} + R^{4/5} Q^{1/10}\right) Q^{o(1)} \,. \end{aligned}$$
(4.2)

In what follows it is convenient to define

$$\begin{aligned} \rho _q = \max _{1\leqslant M,N \leqslant Q} \ \max _{a,h \in \mathbb {Z}_q^{\times }}\, \max _{\varvec{\alpha }, \varvec{\beta }\ \text {as in~(3.2)}}\ \max \left\{ 1, \frac{ \left| W_{a,q}(\varvec{\alpha }, \varvec{\beta }; h,M,N)\right| }{{\mathfrak B}(M,N,Q)} \right\} . \end{aligned}$$

Hence, recalling (3.3), and using \((MN)^{1/4} Q^{-1/4} \leqslant P^{1/4} Q^{-1/4} \ll 1\) we see that for \(q \sim Q\) we can always use the bound

$$\begin{aligned} \begin{aligned}&\left| W_{a,q}(\varvec{\alpha }, \varvec{\beta }; h,M,N)\right| \\&\qquad \leqslant \rho _q (MN)^{3/4} Q^{1/8+o(1)} \left( M^{1/4} Q^{-1/8} + 1\right) \left( N^{1/4} Q^{-1/8} + 1\right) \\&\qquad \leqslant \rho _q (MN)^{3/4} Q^{1/8+o(1)} \left( M^{1/4} Q^{-1/8} + N^{1/4} Q^{-1/8} + 1\right) . \end{aligned} \end{aligned}$$
(4.3)

Our main tool is the bound

$$\begin{aligned} \frac{1}{Q} \sum _{\begin{array}{c} q \sim Q\\ q~\text {prime} \end{array}} \rho _q \leqslant Q^{o(1)} \end{aligned}$$
(4.4)

implied by Lemma 3.1 and the Hölder inequality, combined with (4.3).

4.2 The Heath-Brown identity

To estimate the sum (4.1) we apply the Heath-Brown identity in the form given by [13, Lemma 4.1] (see also [21, Proposition 13.3]) as well as a smooth partition of unity from [12, Lemme 2] (or [13, Lemma 4.3]).

We also fix three parameters L, S and U with

$$\begin{aligned} P\geqslant U \geqslant S \geqslant L \geqslant 1. \end{aligned}$$
(4.5)

to be optimised later and define

(4.6)

We always assume that L exceeds some fixed small power of q so we always have \(J \ll 1\).

Now, we fix a triple \((T, h, \lambda )\) with the largest possible absolute value of \( \widetilde{S}_{\lambda , q}(h,T) \) and as in [13, Lemma 4.3], we decompose \(\widetilde{S}_{\lambda , q}(h,T)\) into a linear combination of \(O(\log ^{2J} q)\) sums with coefficients bounded by \(O(\log q)\),

$$\begin{aligned} \Sigma _q(\textbf{V})&=\sum _{m_1, \ldots , m_J=1}^{\infty } \gamma _1(m_1)\ldots \gamma _J(m_J) \sum _{n_1,\ldots , n_J=1}^\infty \\&\qquad \quad V_1 \left( \frac{n_1}{N_1} \right) \ldots V_J \left( \frac{n_J}{N_J} \right) \sum _{\begin{array}{c} x \in \mathbb {F}_q\\ x^2\equiv \lambda m_1 \ldots m_J n_1 \ldots n_J \pmod q \end{array}} \textbf{e}_q(hx) \, , \end{aligned}$$

where

$$\begin{aligned} \textbf{V}=(M_1,\ldots , M_J,N_1,\ldots ,N_J) \in [1/2,2P]^{2J} \end{aligned}$$
(4.7)

is a 2J-tuple of parameters satisfying

$$\begin{aligned} N_1 \geqslant \ldots \geqslant N_J, \quad M_1,\ldots ,M_J \leqslant P^{1/J},\quad P \ll R \ll P \end{aligned}$$
(4.8)

(implied constants are allowed to depend on J), with

$$\begin{aligned} R = \prod _{i=1}^J M_i \prod _{j =1}^JN_j, \end{aligned}$$
(4.9)

and

  • the arithmetic functions \(m_i \mapsto \gamma _i(m_i)\) are bounded and supported in \([M_i/2,2M_i]\);

  • the smooth functions \(x_i \mapsto V_i(x)\) have support in [1/2, 2] and for any fixed \(\varepsilon > 0\) satisfy

    $$\begin{aligned} V^{(j)}(x) \ll q^{j \varepsilon } \end{aligned}$$

    for all integers \(j \geqslant 0\), where the implied constant may depend on j and \(\varepsilon \).

We recall that the notation \(a \sim A\) is equivalent to \(a \in [A/2, 2A)\). Hence we can rewrite he sum \(\Sigma _q(\textbf{V})\) in the following form

$$\begin{aligned} \Sigma _q(\textbf{V})&= \sum _{\begin{array}{c} m_i \sim M_i, n_i \sim N_i\\ i =1, \ldots J \end{array}} \gamma _1(m_1)\ldots \gamma _J(m_J) V_1 \left( \frac{n_1}{N_1} \right) \ldots V_J \left( \frac{n_J}{N_J} \right) \\&\quad \sum _{\begin{array}{c} x \in \mathbb {F}_q\\ x^2\equiv \lambda m_1 \ldots m_J n_1 \ldots n_J \pmod q \end{array}} \textbf{e}_q(hx)\,. \end{aligned}$$

In particular, we see that the sums \(\Sigma _q(\textbf{V})\) are supported on a finite set. We now collect various bounds on the sums \(\Sigma _q(\textbf{V})\) which we derive in various ranges of parameters \(M_1,\ldots , M_J,N_1,\ldots ,N_J\) until we cover the whole range in (4.7).

4.3 Bounds of multilinear sums

To estimate the multilinear sums \(\Sigma _q(\textbf{V})\), we put \(N_1\) in ranges which we call “small”, “moderate", “large" and “huge”. We further split the “moderate" range in further subranges depending on “small" and “large" values of \(N_2\). These ranges depend on L, S and U in (4.5) and also P and Q and thus in principle some can be empty depending on the choice of L, S and U.

In order to apply Lemma 3.1, it is convenient to observe that in the bound (4.3) we have \(M^{1/4}Q^{-1/8} + 1 \ll 1\) for \(M \ll Q^{1/2}\) and similarly for the other term involving N. It is also convenient to assume that

$$\begin{aligned} P\geqslant Q^{1/2}, \end{aligned}$$
(4.10)

as otherwise the bound of Theorem 1.1 is trivial.

Case I: Small \(N_1\)

First we consider the case when

$$\begin{aligned} N_1 \leqslant L . \end{aligned}$$
(4.11)

From the definition of J in (4.6) and the condition (4.8) we see that

$$\begin{aligned} M_1,\ldots ,M_J \leqslant L . \end{aligned}$$
(4.12)

We see that if the inequality (4.11) holds then we can choose two sets \(\mathcal {I}, \mathcal {J}\subseteq \{1, \ldots , J\}\) such that for

$$\begin{aligned} M = \prod _{i\in \mathcal {I}} M_i \prod _{j \in \mathcal {J}} N_j \qquad \text{ and }\qquad N = R/M , \end{aligned}$$

where R is given by (4.9) we have

$$\begin{aligned} P^{1/2} \ll N \ll L^{1/2}P^{1/2} . \end{aligned}$$
(4.13)

Indeed, we simply start multiplying consecutive elements of the sequence \(M_1,\ldots , M_J\), \(N_1, \ldots ,N_J\) until their product \(R_+\) exceeds \(P^{1/2}\) while the previous product \(R_- < P^{1/2}\). Since by (4.11) and (4.12) each factor is at most L, we have \(R_+ < L R_-\). Hence

  • either we have \(P^{1/2} \leqslant R_+ \leqslant P^{1/2}L^{1/2}\) and then we set \(M= R/R_+\) and \(N = R_+ \);

  • or we have \(P^{1/2}>R_- > L^{-1/2} P^{1/2}\) and then we set \(M = R_-\) and \(N= R/R_-\), where R is given by (4.9).

Hence in either case the corresponding N satisfies the upper bound in (4.13). In this case, since for \(N \gg P^{1/2}\) we have \(M \ll P/N \ll P^{1/2} \ll Q^{1/2}\), recalling (4.3), we have

$$\begin{aligned} \begin{aligned} |\Sigma _q(\textbf{V})|&\leqslant \rho _q P^{3/4} Q^{1/8+o(1)} \left( L^{1/8} P^{1/8}Q^{-1/8}+1\right) \\&= \rho _q \left( L^{1/8} P^{7/8} + P^{3/4} Q^{1/8}\right) Q^{o(1)} . \end{aligned} \end{aligned}$$
(4.14)

Case II: Moderate \(N_1\)

We now consider the case

$$\begin{aligned} L < N_1 \leqslant S . \end{aligned}$$
(4.15)

where we now assume that

$$\begin{aligned} S \leqslant P^{1/2}. \end{aligned}$$
(4.16)

We further split it into two subcases, depending on the size of \(N_2\).

\(\bullet \) SubcaseII.1: Moderate \(N_1\) and small \(N_2\)

If we have

$$\begin{aligned} S \geqslant N_1\geqslant L > N_2 , \end{aligned}$$

then we again start multiplying \(N_1\) by other elements from the sequence \(M_1,\ldots , M_J\), \(N_2, \ldots ,N_J\) and using that (4.10) guarantees that in this range, using (4.16), we have

$$\begin{aligned} \prod _{i=1}^J M_i \prod _{j =2}^JN_j = R/N_1 \geqslant P/S \geqslant P^{1/2} \end{aligned}$$

we can prepare two parameters M and N with (4.13). Therefore, we again have the bound (4.14).

\(\bullet \) SubcaseII.2: Moderate \(N_1\) and \(N_2\)

It remains to consider the case when

$$\begin{aligned} S \geqslant N_1\geqslant N_2 \geqslant L . \end{aligned}$$

In this case, we define M and N as

$$\begin{aligned} M = \prod _{i=1}^J M_i \prod _{j =3}^JN_j \qquad \text{ and }\qquad N = N_1 N_2 \end{aligned}$$

thus we have

$$\begin{aligned} S^2 \geqslant N \geqslant L^2 . \end{aligned}$$

We also note that

$$\begin{aligned} M^{1/4} Q^{-1/8} + N^{1/4} Q^{-1/8}&\ll (P/N) ^{1/4} Q^{-1/8} + N^{1/4} Q^{-1/8} \\&\ll (P/L^2) ^{1/4} Q^{-1/8} + Q^{-1/8} S^{1/2} \\&= L^{-1/2} P^{1/4} Q^{-1/8} + Q^{-1/8} S^{1/2} \,. \end{aligned}$$

Hence, the bound (4.3), implies

$$\begin{aligned} \begin{aligned} |\Sigma _q(\textbf{V})|&\leqslant \rho _q P^{3/4} Q^{1/8} \left( L^{-1/2} P^{1/4} Q^{-1/8}+ Q^{-1/8} S^{1/2} +1\right) \\&= \rho _q\left( L^{-1/2} P + P^{3/4}S^{1/2}+ P^{3/4} Q^{1/8}\right) Q^{o(1)} . \end{aligned} \end{aligned}$$
(4.17)

Case III: Large \(N_1\)

In the case when

$$\begin{aligned} U \geqslant N_1 \geqslant S \end{aligned}$$
(4.18)

we set

$$\begin{aligned} M = \prod _{i=1}^J M_i \prod _{j =2}^JN_j \qquad \text{ and }\qquad N = N_1 . \end{aligned}$$

With the above choice, under the condition (4.18), we have the bounds

$$\begin{aligned} M^{1/4} Q^{-1/8} + N^{1/4} Q^{-1/8}&\ll (P/N) ^{1/4} Q^{-1/8} + N^{1/4} Q^{-1/8} \\&\ll (P/S ) ^{1/4} Q^{-1/8} + U^{1/4} Q^{-1/8} \\&= P^{1/4} Q^{-1/8} S^{-1/4} + U^{1/4} Q^{-1/8} \,. \end{aligned}$$

Therefore, we see that the bound (4.3) implies

$$\begin{aligned} \begin{aligned} |\Sigma _q(\textbf{V})|&\leqslant \rho _q P^{3/4} Q^{1/8+o(1)} \left( P^{1/4} Q^{-1/8} S^{-1/4} + U^{1/4} Q^{-1/8} + 1\right) \\&\leqslant \rho _q \left( P S^{-1/4} + P^{3/4} U^{1/4} + P^{3/4} Q^{1/8}\right) Q^{o(1)} . \end{aligned} \end{aligned}$$
(4.19)

Case IV: Huge \(N_1\)

We now consider the case when

$$\begin{aligned} U <N_1 \leqslant P . \end{aligned}$$
(4.20)

In this case, via partial summation and an application of Lemma 3.4, exactly as in [11]

$$\begin{aligned} \begin{aligned} |\Sigma _q(\textbf{V})|&\leqslant M_1 \ldots M_J N_2 \ldots N_J q^{1/2+o(1)} \\&= P N_1^{-1} q^{1/2+o(1)} \leqslant \rho _qP U^{-1} Q^{1/2+o(1)} . \end{aligned} \end{aligned}$$
(4.21)

4.4 Optimisation

We observe that the bounds (4.14), (4.17), (4.19) and (4.21) cover all four possiblee ranges of \(N_1\) given by (4.11), (4.15), (4.18) and (4.20).

We now choose L to balance its contribution to the bounds (4.14) and (4.17). This leads us to the equation

$$\begin{aligned} L^{1/8} P^{7/8} = L^{-1/2} P . \end{aligned}$$

Thus, we choose

$$\begin{aligned} L= P^{1/5} , \end{aligned}$$

in which case the bound (4.17) always dominatess (4.14) (as it has one extra term) and hence both can be combined as

$$\begin{aligned} |\Sigma _q(\textbf{V})| \leqslant \rho _q \left( P^{9/10} + P^{3/4}S^{1/2}+ P^{3/4} Q^{1/8}\right) Q^{o(1)} . \end{aligned}$$
(4.22)

We also have \(J \ll 1\) as required.

We now choose S to balance its contribution to the bounds (4.19) and (4.22). That is, we choose it as \(S= P^{1/3}\) from the equation

$$\begin{aligned} P S^{-1/4} = P^{3/4}S^{1/2}, \end{aligned}$$

and note that this choice of S also satisfies (4.16). Hence the bounds (4.19) and (4.22) (after discarding the term \(P^{9/10}\)) can now be combined as

$$\begin{aligned} |\Sigma _q(\textbf{V})| \leqslant \rho _q \left( P^{11/12}+ P^{3/4} U^{1/4} + P^{3/4} Q^{1/8}\right) Q^{o(1)} . \end{aligned}$$
(4.23)

We also choose U to balance its contribution to the bounds (4.21) and (4.23). This leads us to the equation

$$\begin{aligned} P U^{-1} Q^{1/2} = P^{3/4} U^{1/4} . \end{aligned}$$

Thus, we choose

$$\begin{aligned} U= P^{1/5} Q^{2/5} , \end{aligned}$$

in which case the bound (4.23) dominates (4.21) and both can be combined as

$$\begin{aligned} |\Sigma _q(\textbf{V})| \leqslant \rho _q \left( P^{11/12} + P^{4/5} Q^{1/10} + P^{3/4} Q^{1/8}\right) Q^{o(1)} . \end{aligned}$$
(4.24)

One easily checks (after recalling that by (4.10) we have \(Q \geqslant P\geqslant Q^{1/2}\)) that the above choices of L, S and U satisfy (4.5).

We now note that under the condition (4.10) we have

$$\begin{aligned} P^{4/5} Q^{1/10} \geqslant P^{3/4} Q^{1/8} . \end{aligned}$$

Therefore the bound (4.24) implies that

$$\begin{aligned} |\Sigma _q(\textbf{V})| \leqslant \rho _q \left( P^{11/12} + P^{4/5} Q^{1/10} \right) Q^{o(1)} \end{aligned}$$

for all data \(\textbf{V}\) and hence we obtain (4.2).

4.5 Concluding the proof

Combining the bound (4.2) with (4.4) and Lemma 3.3, we instantly derive the desired statement for \(\Gamma _{\lambda , q}(P)= \Delta _{\lambda , q}(P)\). For \(\Gamma _{\lambda , q}(P)= \widetilde{\Delta }_{\lambda , q}(P)\) we also recall Lemma 3.2.

5 Possible generalisations

First we note that our proof of Theorem 1.1 can easily be adjusted to produce the following more general estimate

$$\begin{aligned} \frac{1}{Q} \sum _{\begin{array}{c} q \leqslant Q\\ q~\text {prime} \end{array}} \max _{T \leqslant P} \max _{\lambda \in \mathbb {Z}_q^\times } \Gamma _{\lambda , q}(T) \leqslant P \left( P^{-1/12} + P^{-1/5} Q^{1/10}\right) Q^{o(1)} . \end{aligned}$$

It is natural to ask whether our results and methods can be used to treat higher degree roots of primes, that is, to ask about the distribution of roots of congruences

$$\begin{aligned} x^d \equiv p \pmod q, \end{aligned}$$

with an integer \(d \geqslant 3\).

To address this question, we recall that one of the crucial ingredients in the proof of Theorem 1.1 is a result of Heath-Brown [17] on average values of sums of real characters. Similar, albeit weaker, results are also known for cubic and quartic characters, see [2, 15, 18], however we are unaware of any result for higher order characters. This can limit the abilities of what one can realistically hope to prove nowadays to \(d \leqslant 4\), unless one assumes the Generalised Riemann Hypothesis, which instantly gives such a necessary result for each q (without any need for averaging), see [21, Sections 5.8 and 5.9].

The second ingredient is provided by bounds of bilinear sums with roots which in turn is based on bounds on the additive energy of roots. The case of square-roots allows a special treatment, see [11, 32], however higher degree roots can be studied as well. To illustrate this we consider the congruence with cubic roots

$$\begin{aligned} x+y \equiv a \pmod q, \qquad x^3, y^3 \in [1,N], \end{aligned}$$
(5.1)

where the cubes are computed modulo q. From (5.1) we derive

$$\begin{aligned} a^3 \equiv (x+y)^3 = x^3 + y^3 + 3axy \pmod q \end{aligned}$$

and then

$$\begin{aligned} 27a^3 x^3y^3 \equiv \left( a^3 - x^3 - y^3\right) ^3 \pmod q. \end{aligned}$$

Denoting \(U = x^3y^3\) and \(V = x^3 + y^3\) we arrive to the congruence

$$\begin{aligned} \left( a^3 - V\right) ^3 \equiv 27a^3 U \pmod q \end{aligned}$$

with \(V \in [1, 2N]\), \(U \in [1, N^2]\) to which, provided \(N^2 = o(p)\), the methods of [3, 4] can be applied. Quite to the contrary to above limitation \( d\leqslant 4\), we believe that this part can be extended to arbitrary \(d \geqslant 2\).