/- Copyright 2026 The Formal Conjectures Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -/ module public import FormalConjecturesUtil

Erdős Problem 980

References:

    erdosproblems.com/980

    [El67b] Elliott, P. D. T. A., A problem of Erdős concerning power residue sums. Acta Arith. 13 (1967/68), 131-149.

    [Er61e] Erdős, P., Remarks on number theory. I. Mat. Lapok (1961), 10-17.

    [Er65b] Erdős, P., Some recent advances and current problems in number theory. Lectures on Modern Mathematics, Vol. III (1965), 196-244.

    [MaPo11] Martin, G. and Pollack, P., The average least character nonresidue and further variations on a theme of Erdős. arXiv:1112.1175 (2011).

@[expose] public sectionopen Filter Asymptoticsnamespace Erdos980

$n_k(p)$: the least positive integer which is not a $k$-th power residue modulo $p$. If every integer is a $k$-th power residue (for example if $\gcd(k, p - 1) = 1$) the value is $0$; this does not happen for the primes $p \equiv 1 \pmod k$ with $k \geq 2$ used below.

noncomputable def leastNonresidue (k p : ℕ) : ℕ := sInf {n : ℕ | 0 < n ∧ ¬ ∃ x : ZMod p, x ^ k = (n : ZMod p)}

$\sum n_k(p)$ over the primes $p < x$ with $p \equiv 1 \pmod k$.

noncomputable def residueSum (k : ℕ) (x : ℝ) : ℝ := ∑ p ∈ (Nat.primesBelow ⌈x⌉₊).filter (fun p ↦ p % k = 1), (leastNonresidue k p : ℝ)

$2$ is the least quadratic nonresidue modulo $3$.

h2:2 ∈ {n | 0 < n ∧ ¬∃ x, x ^ 2 = ↑n}n:ℕhn:0 < nhn':¬∃ x, x ^ 2 = ↑nh:n < 2h1:n = 1⊢ False h2:2 ∈ {n | 0 < n ∧ ¬∃ x, x ^ 2 = ↑n}hn:0 < 1hn':¬∃ x, x ^ 2 = ↑1h:1 < 2⊢ False exact hn' ⟨1, h2:2 ∈ {n | 0 < n ∧ ¬∃ x, x ^ 2 = ↑n}hn:0 < 1hn':¬∃ x, x ^ 2 = ↑1h:1 < 2⊢ 1 ^ 2 = ↑1 All goals completed! 🐙⟩

Let $k\geq 2$ and $n_k(p)$ denote the least $k$th power nonresidue of $p$. Is it true that $$\sum_{p<x} n_k(p)\sim c_k \frac{x}{\log x}$$ for some constant $c_k>0$?

Erdős [Er65b] asked this; it is true, and was proved by Elliott [El67b]. As in [El67b], the sum is over the primes $p \equiv 1 \pmod k$ (for each of which a $k$th power nonresidue exists).

@[category research solved, question, AMS 11] theorem erdos_980 (k : ℕ) (hk : 2 ≤ k) : ∃ c > (0 : ℝ), residueSum k ~[atTop] fun x ↦ c * x / Real.log x := k:ℕhk:2 ≤ k⊢ ∃ c > 0, residueSum k ~[atTop] fun x ↦ c * x / Real.log x All goals completed! 🐙

Erdős [Er61e] proved this when $k=2$, with $$c_2=\sum_{k=1}^\infty \frac{p_k}{2^k},$$ where $p_k$ is the $k$th prime; the sum is over the odd primes $p < x$ [MaPo11, (1.1)].

@[category research solved, AMS 11] theorem erdos_980.variants.erdos_two : residueSum 2 ~[atTop] fun x ↦ (∑' i : ℕ, (Nat.nth Nat.Prime i : ℝ) / 2 ^ (i + 1)) * x / Real.log x := ⊢ residueSum 2 ~[atTop] fun x ↦ (∑' (i : ℕ), ↑(Nat.nth Nat.Prime i) / 2 ^ (i + 1)) * x / Real.log x All goals completed! 🐙end Erdos980