/-
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 FormalConjecturesUtilNumber of positive integers $k < n$ such that $n^2 - \pi(k n)$ is prime
The sequence $a(n)$ counts the number of positive integers $k < n$ such that $n^2 - \pi(k n)$ is prime, where $\pi(x)$ is the prime counting function: $$a(n) = |{0 < k < n : n^2 - \pi(k n) \text{ is prime}}|$$
References:
Problems on combinatorial properties of primes by Zhi-Wei Sun (2014)
@[expose] public sectionnamespace OeisA238568open FinsetNumber of positive integers $k < n$ such that $n^2 - \pi(k n)$ is prime.
def a (n : ℕ) : ℕ :=
((Ico 1 n).filter fun k => Nat.Prime (n ^ 2 - Nat.primeCounting (k * n))).card@[category test, AMS 11]
theorem a_1 : a 1 = 0 := ⊢ a 1 = 0
All goals completed! 🐙@[category test, AMS 11]
theorem a_2 : a 2 = 1 := ⊢ a 2 = 1
All goals completed! 🐙@[category test, AMS 11]
theorem a_3 : a 3 = 1 := ⊢ a 3 = 1
All goals completed! 🐙@[category test, AMS 11]
theorem a_4 : a 4 = 1 := ⊢ a 4 = 1
All goals completed! 🐙@[category test, AMS 11]
theorem a_5 : a 5 = 2 := ⊢ a 5 = 2
All goals completed! 🐙Conjecture (i): $a(n) > 0$ for all $n > 1$.
@[category research open, AMS 11]
theorem conjecture_1 (n : ℕ) (hn : 1 < n) : 0 < a n := n:ℕhn:1 < n⊢ 0 < a n
All goals completed! 🐙Conjecture (i): $a(n) = 1$ only for $n \in {2, 3, 4, 8, 10, 24, 41}$.
@[category research open, AMS 11]
theorem conjecture_2 (n : ℕ) :
a n = 1 ↔ n ∈ ({2, 3, 4, 8, 10, 24, 41} : Set ℕ) := n:ℕ⊢ a n = 1 ↔ n ∈ {2, 3, 4, 8, 10, 24, 41}
All goals completed! 🐙Conjecture (ii): For any integer $n > 6$, there is a positive integer $k < n$ with $n^2 + \pi(k n) - 1$ prime.
@[category research open, AMS 11]
theorem conjecture_3 (n : ℕ) (hn : 6 < n) :
∃ k : ℕ, 0 < k ∧ k < n ∧ Nat.Prime (n ^ 2 + Nat.primeCounting (k * n) - 1) := n:ℕhn:6 < n⊢ ∃ k, 0 < k ∧ k < n ∧ Nat.Prime (n ^ 2 + (k * n).primeCounting - 1)
All goals completed! 🐙Conjecture (iii), part 1: If $n > 2$, then $\pi(n^2) - \pi(k n)$ is prime for some $0 < k < n$.
@[category research open, AMS 11]
theorem conjecture_4 (n : ℕ) (hn : 2 < n) :
∃ k : ℕ, 0 < k ∧ k < n ∧
Nat.Prime (Nat.primeCounting (n ^ 2) - Nat.primeCounting (k * n)) := n:ℕhn:2 < n⊢ ∃ k, 0 < k ∧ k < n ∧ Nat.Prime ((n ^ 2).primeCounting - (k * n).primeCounting)
All goals completed! 🐙Conjecture (iii), part 2: If $n > 1$, then $\pi(n^2) + \pi(k n) - 1$ is prime for some $0 < k < n$.
@[category research open, AMS 11]
theorem conjecture_5 (n : ℕ) (hn : 1 < n) :
∃ k : ℕ, 0 < k ∧ k < n ∧
Nat.Prime (Nat.primeCounting (n ^ 2) + Nat.primeCounting (k * n) - 1) := n:ℕhn:1 < n⊢ ∃ k, 0 < k ∧ k < n ∧ Nat.Prime ((n ^ 2).primeCounting + (k * n).primeCounting - 1)
All goals completed! 🐙end OeisA238568