3

We all know that $a$ is a quadratic residue modulo $p$ if and only if $a^{(p-1)/2} \equiv 1 \pmod p$,

also $a$ is a cubic residue modulo $p$ if and only if $a^{(p-1)/3} \equiv 1 \pmod p$.

Now, for a given prime $p$:

(1) is there any way to predict the largest number of consecutive quadratic residues modulo $p$?

for example, the largest number of consecutive quadratic residues modulo $103$ is 7, since $\{13, 14, 15, 16, 17, 18, 19\}$ are quadratic residue modulo $103$.

(2) is there any way to predict the largest number of consecutive cubic residues modulo $p$?

for example, the largest number of consecutive cubic residues modulo $73$ is 4, since $\{7, 8, 9, 10\}$ or $\{63, 64, 65, 66\}$ are cubic residues modulo $73$

(3) can I predict (or give an upper bond to) the number of quadratic residues sequences of the length $n$?

for example, there are $12$ quadratic residues sequences of the length $3$ (modulo $103$).

(4) can I predict (or give an upper bond to) the number of cubic residues sequences of the length $n$?

for example, there are $17$ cubic residues sequences of the length $4$ (modulo $997$).

  • 4
    A long string of quadratic residues would yield a large incomplete character sum on the Legendre character. An upper bound for such sums can be given with the Polya-Vinogradov method. But the resulting upper bounds for the length of such strings have the form $\mathcal{O}(\ln p \sqrt p)$. A similar bound can be obtained for cubic residues, as well as for cubic non-residues. For strings of quadratic non-residues we have a trivial $\mathcal{O}(\sqrt p)$ bound. I don't think Polya-Vinogradov is believed to be even nearly tight. Over to people who actually know this stuff :-) – Jyrki Lahtonen Aug 16 '22 at 13:39
  • 7
    https://oeis.org/A002307 is "Consecutive quadratic residues mod $p$: $a(n)$ is the maximal number of positive reduced quadratic residues which appear consecutively for $n$-th prime." There are links to the literature there. – Gerry Myerson Aug 16 '22 at 13:51
  • Have you had a look at that link I gave? – Gerry Myerson Aug 18 '22 at 03:31
  • @GerryMyerson I am really sorry sir, but I can't take a look at your link (since I have some problems with my browser), but if there is any possibility that you kindly put the answer here, that would be a great thing, thank you sir – عبد الرحمن رمزي محمود Aug 18 '22 at 14:58
  • @JyrkiLahtonen thank you very much, and I will try to take a look at some references – عبد الرحمن رمزي محمود Aug 19 '22 at 15:32

2 Answers2

4

At https://oeis.org/A002307 there is a link https://www.ams.org/journals/bull/1926-32-03/S0002-9904-1926-04211-7/ to A. A. Bennett, Consecutive quadratic residues, Bull. Amer. Math. Soc. 32 (1926), 283-284, DOI: https://doi.org/10.1090/S0002-9904-1926-04211-7.

The introduction states,

"I have succeeded in proving that for each prime greater than $193$ there is at least one sequence of five consecutive positive reduced quadratic residues. The proof entails the examination of many hundred linear forms which together include all primes. Since the method would prove excessively laborious for even the next case, that of six consecutive quadratic residues, the computational details seem hardly to warrant the space required for their complete publication."

Bennett further writes that, looking at the primes up to $317$, the length of the longest run of quadratic residues modulo $p$ "is fairly closely approximated by" $(1/2)\sqrt{p+20\log_{10}p}$.

Personally, I wouldn't put too much confidence in any estimate backed up by the primes up to $317$.

The oeis link also attributes to Jonathan Sondow a claim that the length is bounded by $2\sqrt p$, but no proof is given.

https://oeis.org/A002307/b002307.txt tabulates the length of the longest run of residues for the first $10,000$ primes.

https://oeis.org/A097159 tabulates "Smallest prime $p$ such that there are $n$ consecutive quadratic residues mod $p$" up to $n=33$; here it is:

$2, 7, 11, 19, 43, 67, 83, 131, 283, 277, 467, 479, 1907, 1607, 2543, 1559, 5443, 5711, 6389, 14969, 25703, 10559, 20747, 52057, 136223, 90313, 162263, 18191, 167107, 31391, 376589, 607153, 671947.$

So, e.g., the smallest prime with two consecutive residues is $7$, the smallest with three consecutive is $11$, ..., the smallest with $33$ consecutive is $671947$. Note the list is not strictly increasing; $283$ has nine consecutive, but the smaller prime $277$ has ten.

There is also a comment, $a(35)=298483$, $a(36)=422231$, $a(40)=701399$ and $a(42)=366791$.

Also relevant is https://oeis.org/A097160, "Greatest prime $p$ such that there are $n$, but not $n+1$, consecutive quadratic residues mod $p$, or $-1$ if no such prime exists." This list is very short: $5, 17, 53, 193, 457, 2153$. It is conjectured that it continues $4481, 9857, 25793, 60961, 132113, 324673$. A proof is given that $17$ is the largest prime with two, but not three, consecutive residues. The proof is too long to be included here.

There is a reference to Alfred Brauer, Ueber Sequenzen von Potenzresten, S.-B. Deutsch. Akad. Wiss. Berlin 1928, 9-16, and a link to D. H. Lehmer and Emma Lehmer, On Runs of Residues, Proc. Amer. Math. Soc, Vol. 13, No. 1 (Feb., 1962), pp. 102-106. The link is https://www.ams.org/journals/proc/1962-013-01/S0002-9939-1962-0138582-6/home.html

There is also https://oeis.org/A097161 "Number of primes modulo which the largest number of consecutive quadratic residues is $n$," but some of the entries in this list may be unproved.

Concerning higher power residues, there is https://oeis.org/A000236 "Maximum $m$ such that there are no two adjacent elements belonging to the same $n$-th power residue class modulo some prime $p$ in the sequence $1,2,...,m$" I don't know whether there are other oeis entries for higher power residues.

Gerry Myerson
  • 185,413
3

A useful exact formula is unlikely; it might even be unknown how to compute this number in time much less than $p$. But we can still give heuristic estimates and compare them with known theorems.

Typically we expect $\log_2 p$ for consecutive quadratic residues, and $\log_3 p$ for consecutive cubic residues, because the number of stretches of $n$ consecutive quadratic (cubic) residues should be about $p/2^n$ (resp. $p/3^n$) on average. For example, if $p = 10^6 + 7$ (the first seven-digit prime) then the quadratic-residue counts for $n \leq 20$ are

500001, 250000, 125000, 62536, 31286, 15606, 7804, 3908, 1951, 948, 
481, 249, 126, 64, 36, 20, 11, 4, 2, 0

The two survivors for $n=19$ start at $295213$ and $860213$.

Using the (Hasse-)Weil bound (1949), we can show that the actual counts differ from $p/2^n$ and $p/3^n$ by $O(n \sqrt p)$, so we're always guaranteed a stretch of length at least $(\frac12 - o(1)) \log_2 p$ or $(\frac12 - o(1)) \log_3 p$. To apply the Weil bound for quadratic residues (the cubic case is similar), let $\chi$ be the quadratic character $\bmod p$, and write the number of $a \bmod p$ such that $\chi(a+i) = 1$ for each $i=1,2,\ldots,n$ as $$ 2^{-n} \sum_{a \bmod p} \prod_{i=1}^n \bigl(1 + \chi(a+i) \bigr) $$ up to an error of at most $n$ from the $n$ values of $a$ such that some $a+i = 0$. Now expand the product over $i$ into $2^n$ terms; the term $1$ sums to $p$, and each of the remaining terms has absolute value less than $n \sqrt p$ by Weil. Exact formulas are known only for $n \leq 3$. For example, the number of consecutive triples of quadratic residues mod $p$ is $\lfloor p/8\rfloor$ if $p \equiv 3 \bmod 4$; if $p \equiv 1 \bmod 4$ there's a more complicated formula involving the Fermat decomposition of $p$ as a sum of two squares.

Upper bounds are harder. Varying $p$ gives us about $x^2 / (2 \log x)$ chances with $p \leq x$, which roughly doubles the maximal expected lengths to about $2 \log_2 x$ and $2 \log_3 x$. We might be able to squeeze out a $\log \log x$ factor by looking at the first $p$ at which each of the first $n$ primes $2,3,5,\ldots$ is a quadratic (cubic) residue; if this $p$ is typically proportional to $n 2^n$ (resp. $n 3^n$) then we get consecutive quadratic (cubic) residues up to the $n$-th prime, which is about $n \log n$. Note that this trick is not applicable to "quadratic (cubic) non-residues".

By the Burgess bounds (1963) on $\sum_{i=1}^n \chi(a+i)$, for each $\epsilon > 0$ there's an effective constant $C_\epsilon$ such that the number of consecutive quadratic or cubic residues $\bmod p$ is $< C_\epsilon p^{1/4 + \epsilon}$. This is surely very far from sharp for large $p$, though it's still more than enough to refute the guess of $\sim \frac12 \sqrt p$ (Bennett 1926) reported by Gerry Myerson.