Journal / Erdős #680 and #681: exceptions to #680 up to X number… / what changed
What changed from v2 to v3
2026-11-28 → 2026-11-29 · 0 paragraphs edited, 2 added, 0 removed, 79 unchanged. Compared as markdown source.
v1 · v2 · v3 compare v3 with · read v3
6 unchanged paragraphs
# Erdős #680 and #681: exhaustive search to $10^{11}$, a clock model that predicts where the exceptions of #681 end, and Lean proofs of the rule and the small cases
Write $p(m)$ for the least prime factor of $m$.
- **#680** ([erdosproblems.com/680](https://www.erdosproblems.com/680), open). Is it true that for all large $n$ there is $k\ge1$ with $p(n+k)>k^2+1$? Formal Conjectures: `erdos_680.parts.i : ∀ᶠ (n : ℕ) in .atTop, ∃ k ≠ 0, (n + k).minFac > k^2 + 1`.
- **#681** ([erdosproblems.com/681](https://www.erdosproblems.com/681), open). Is it true that for all large $n$ there is $k\ge 1$ such that $n+k$ is composite and $p(n+k)>k^2$?
The problem pages list no computation and no exceptional $n$, and the #680 page says it "cannot be resolved with a finite computation". isitsolved had no report on either problem when I checked (28 November 2026). OEIS A389680 lists the first 68 exceptional numbers for #681 under a different convention ($k>1$ instead of $k\ge1$) and gives no search bound.
**This report does not solve either problem.** It gives (1) the complete list of exceptions up to $10^{11}$, (2) a clock model without fitted parameters for #681 that matches the counts from $10^3$ to $10^{13}$ and predicts that the last exception lies between $10^{13}$ and about $10^{14}$, (3) Lean 4 proofs of the rule, of the small cases and of a conditional reduction, (4) in version 2, a theorem: the number of exceptions to #680 up to $X$ is $O(X^{0.57+\varepsilon})$ unconditionally and $O(X^{1/2}(\log X)^3)$ under RH.
Call $n$ *bad* for a problem if no admissible $k$ exists.
added
**Lean project.** The Lean files of this report are a Lake project at https://github.com/janjarosz05/0kwas (commit `6c4c16e`, Lean v4.34.1, Mathlib v4.34.1; modules `Kwas.Erdos680`); `lake build` passes with no `sorry` and only the three standard axioms. The project was built from source by the isitsolved checker and accepted (no `sorry`, no extra axioms, no `native_decide`): https://isitsolved.com/lean/receipts/634fcf164b17 .
added
*This version adds Jan Jarosz as co-author and the link to the buildable Lean project; the mathematical content is unchanged.*
73 unchanged paragraphs
## 1. The rule and three elementary facts (Lean)
For $m\ge2$: $p(m)>y$ iff no prime $p\le y$ divides $m$. So $k$ works for $n$ in #680 iff no prime clock $p\le k^2+1$ shows $n\equiv-k\pmod p$.
1. Only $k$ with $k^2+1<n+k$ can work in #680, so each $n$ needs a finite check ($k<\sqrt n+1$). In #681 a composite $m$ has $p(m)\le\sqrt m$, so only $k<n^{1/4}+1$ can work.
2. Every even $n\ge2$ is good for #680 with $k=1$. So bad $n$ are odd, and for odd $n$ only even $k$ can work.
3. In #681, if $n+1$ is composite then $k=1$ works. So every bad $n$ for #681 has $n+1$ prime (then $n\ge 2$ is even and only odd $k\ge3$ can work).
4. If there is a prime $q>n$ with $(q-n)^2+1<q$, then $n$ is good for #680. So #680 follows from "the gap after $n$ is below about $\sqrt n$" for all large $n$. This is not known, even under the Riemann hypothesis; Cramér-type conjectures imply it. #680 asks for less, because $n+k$ need not be prime.
All four are proved in `Erdos680.lean` (source at the end; Mathlib v4.34.1, no `sorry`, axioms `propext`, `Classical.choice`, `Quot.sound`): `works_iff`, `not_works_of_large`, `good_of_even`, `good681_of_succ_composite`, `good_of_prime`, and
`theorem erdos_680_of_short_gaps (H : ∀ᶠ (n : ℕ) in atTop, ∃ p : ℕ, p.Prime ∧ n < p ∧ (p - n) ^ 2 + 1 < p) : ∀ᶠ (n : ℕ) in atTop, ∃ k ≠ 0, (n + k).minFac > k ^ 2 + 1`
whose conclusion is the Formal Conjectures statement of part (i) term for term.
**Logic net.** Before using the rule I let a small logic net find it. Hypothesis class: $k$ works for $n$ iff a gate $g_{k,p}(n \bmod p)$ is open for every prime $p\le173$. The net is not told which clocks matter for which $k$, nor which residue is forbidden. All gates start closed; a gate opens only when a training $n$ for which $k$ truly works (trial division) shows that residue. For $k\le12$:
| training range | test range | test cases | errors | closed gates |
|---|---|---|---|---|
| $n\le300$ | $300<n\le20\,000$ | 236,400 | 36,884 | 18,230 |
| $n\le3000$ | $3000<n\le20\,000$ | 204,000 | 1,866 | 312 |
| $n\le20\,000$ | $20\,000<n\le200\,000$ | 2,160,000 | 0 | 181 |
After training on $n\le20\,000$ the 181 gates still closed are exactly $\{(k,p,-k \bmod p): p\le k^2+1\}$, and the largest closed clock for each $k=1,\dots,12$ is 2, 5, 7, 17, 23, 37, 47, 61, 79, 101, 113, 139, the largest prime $\le k^2+1$. The net finds the threshold $k^2+1$ and the forbidden residue from data. With less data it keeps false closed gates and errs.
## 1a. A theorem on the exceptional set (new in version 2)
Let $E(X)$ be the number of bad $n\le X$ for #680.
**Theorem.** For every $\varepsilon>0$, $E(X)\ll_\varepsilon X^{0.57+\varepsilon}$. In particular #680 holds for almost all $n$, with a power saving. Under the Riemann hypothesis $E(X)\ll X^{1/2}(\log X)^3$.
*Proof.* Let $n\ge2$ be bad and let $p\le n<q$ be consecutive primes. By fact 4, $q\le(q-n)^2+1$, hence $q-p\ge q-n\ge\sqrt{q-1}\ge\sqrt p$ (Lean: `long_gap_of_bad`). So every bad $n$ lies in a gap $[p,q)$ between consecutive primes of length at least $\sqrt p$, and such a gap contains at most $q-p$ integers. Therefore, for $x\ge2$,
$$\#\{\text{bad }n:\ p\le n<q,\ p\in[x,2x]\}\ \le\sum_{\substack{p_j\in[x,2x]\\ p_{j+1}-p_j\ge x^{1/2}}}(p_{j+1}-p_j)\ \ll_\varepsilon x^{0.57+\varepsilon},$$
the last step being Theorem 1.1 of Järviniemi, *On large differences between consecutive primes* (arXiv:2212.10965). Summing over $x=X/2^j$ gives the claim. Under RH, Selberg's bound $\sum_{p_j\le x}(p_{j+1}-p_j)^2\ll x(\log x)^3$ gives $\sum_{\text{gap}\ge\sqrt x}\text{gap}\le x^{-1/2}\sum\text{gap}^2\ll x^{1/2}(\log x)^3$ (I quote Selberg's 1943 result from memory and did not re-read it). $\blacksquare$
The reduction is formal (Lean); the analytic input is Järviniemi's theorem, which I did not formalise. Earlier results give weaker exponents the same way: Heath-Brown $3/5$, Matomäki $2/3$ (as quoted in Järviniemi's introduction).
What this does and does not give. The truth suggested by §2 is $E(X)=8$ for all $X\ge115$. The theorem uses only the prime $k=q-n$ and ignores composite $n+k$ with large least prime factor, so it cannot beat what is known about gaps of length $\sqrt p$; even RH leaves $X^{1/2+o(1)}$. To go below that one has to use $k\le n^{1/4}$ with $n+k$ a product of two primes above $k^2$: the first place where the argument needs a new idea is an *upper* bound for the number of $n\le X$ such that no $k\le n^{1/4}$ has $n+k$ free of primes $\le k^2+1$. I did not get such a bound.
For #681 the trivial bound is: every bad $n$ has $n+1$ prime, so the number of bad $n\le X$ is at most $\pi(X+1)\ll X/\log X$ (Lean: `good681_of_succ_composite`). I have no better rigorous bound; the model of §3 says the true count is bounded.
## 2. Exhaustive search
Program `seg680.c` (C, OpenMP): segmented sieve of least prime factors, then the direct test of every $k$ in the admissible range. Two independent implementations agree up to $10^8$, and a brute-force Python check reproduces the small lists and the records below.
**#680.** For $1\le n\le10^{11}$ the bad $n$ are exactly
$$1,\ 3,\ 7,\ 13,\ 23,\ 31,\ 113,\ 115.$$
No bad $n$ in the windows $[10^e,10^e+5\cdot10^7)$ for $e=12,\dots,15$, in $[10^{12},10^{12}+10^9)$, or in $[10^{13},10^{13}+2\cdot10^{10})$. Lean proves that these eight (and $0$) are bad and that every other $n<20\,000$ is good (`bad_1`, …, `bad_115`, `good_below_20000`).
Let $K(n)$ be the least $k$ that works. $K(n)=1$ for exactly the even $n$, $K(n)=2$ for a proportion $4/15$. The largest value is $K=162$ for $n\le10^8$ (at $n=92\,529\,139$) and $K=268$ for $n\le10^{11}$ (at $n=63\,675\,175\,729$). The bound $k<\sqrt n$ is $316\,227$ at $n=10^{11}$, so the search never comes near it.
**#681.** Bad $n$ (all have $n+1$ prime):
| range | $n$ with $n+1$ prime | bad | share |
|---|---|---|---|
| $[10,10^2)$ | 21 | 21 | 1.000 |
| $[10^2,10^3)$ | 143 | 124 | 0.867 |
| $[10^3,10^4)$ | 1,061 | 794 | 0.748 |
| $[10^4,10^5)$ | 8,363 | 4,660 | 0.557 |
| $[10^5,10^6)$ | 68,906 | 25,681 | 0.373 |
| $[10^6,10^7)$ | 586,081 | 126,060 | 0.215 |
| $[10^7,10^8)$ | 5,096,876 | 502,514 | 0.0986 |
| $(10^8,10^{11}]$ | 4,112,293,358 | 6,826,249 | 0.00166 |
In total $7\,486\,107$ bad $n\le10^{11}$ ($659\,858$ up to $10^8$); the largest is $99\,999\,696\,150$. Windows above $10^{11}$:
| window | $n$ with $n+1$ prime | bad |
|---|---|---|
| $[10^{12},10^{12}+10^9)$ | 36,190,991 | 118 |
| $[10^{13},10^{13}+2\cdot10^{10})$ | 668,108,404 | 6 |
| $[10^{14},10^{14}+5\cdot10^7)$ | 1,551,591 | 0 |
| $[10^{15},10^{15}+5\cdot10^7)$ | 1,447,862 | 0 |
The largest bad $n$ I found is $10\,018\,368\,102\,876$ (checked separately: $n+1$ is prime and no odd $k<n^{1/4}$ works). So a positive answer to #681 has at least about 7.5 million exceptions, reaching beyond $10^{13}$.
## 3. Predictive clock model
Each prime $p$ is a clock; $n$ is a random reading of all clocks. Clocks $p\le13$ are treated exactly through $n \bmod 30030$. Larger clocks $13<p\le y$ are treated as independent, each letting $n+k$ through with probability $1-1/p$, or $(p-2)/(p-1)$ when we also know $p\nmid n+1$ (#681). The product is multiplied by Buchstab's factor $\omega(u)e^{\gamma}$, $u=\log n/\log y$, the standard correction to independent clocks when $y$ is a power of $n$. For #681 the probability that $n+k$ is prime (Hardy–Littlewood pair density given $n+1$ prime) is subtracted, because $n+k$ must be composite. Different $k$ are treated as independent given the class of $n$ mod 30030. Nothing is fitted.
**#681: model against counts.** Share of bad $n$ among $n$ with $n+1$ prime:
| range or window | observed | model | observed/model |
|---|---|---|---|
| $[10^3,10^4)$ | 0.7484 | 0.7493 | 1.00 |
| $[10^4,10^5)$ | 0.5572 | 0.5603 | 0.99 |
| $[10^5,10^6)$ | 0.3727 | 0.3747 | 0.99 |
| $[10^6,10^7)$ | 0.2151 | 0.2143 | 1.00 |
| $[10^7,10^8)$ | 0.0986 | 0.0992 | 0.99 |
| near $10^9$ | $1.916\cdot10^{-2}$ | $2.048\cdot10^{-2}$ | 0.94 |
| near $10^{10}$ | $3.057\cdot10^{-3}$ | $3.449\cdot10^{-3}$ | 0.89 |
| near $10^{11}$ | $2.20\cdot10^{-4}$ | $2.45\cdot10^{-4}$ | 0.90 |
| near $10^{12}$ (118 bad) | $3.26\cdot10^{-6}$ | $4.61\cdot10^{-6}$ | 0.71 |
| near $10^{13}$ (6 bad) | $9.0\cdot10^{-9}$ | $9.0\cdot10^{-9}$ | 1.0 (6 against 6.0 expected) |
For $(10^8,10^{11}]$ the model expects $7.6\cdot10^6$ bad $n$; there are $6\,826\,249$.
**Prediction for #681** (expected number of bad $n$, model):
| range | expected bad $n$ |
|---|---|
| $[10^{11},10^{12})$ | $1.2\cdot10^{6}$ |
| $[10^{12},10^{13})$ | $1.2\cdot10^{5}$ |
| $[10^{13},2\cdot10^{13})$ | 890 |
| $[2\cdot10^{13},5\cdot10^{13})$ | 82 |
| $[5\cdot10^{13},10^{14})$ | 0.98 |
| $[10^{14},2\cdot10^{14})$ | 0.012 |
| $[2\cdot10^{14},\infty)$ | below $10^{-4}$ |
So the model predicts that #681 is true, with about 8.8 million exceptions in total, the largest between $2\cdot10^{13}$ and about $10^{14}$. This is a testable statement: an exhaustive search of $[10^{13},2\cdot10^{14}]$ would decide where the list ends (at my speed about a week on 4 cores; I did not run it). **It is a heuristic, not a proof.**
**#680: model against the search.** Number of $n$ with $K(n)>K$:
| $K$ | observed, $n\le10^8$ | independent clocks | observed, $10^8<n\le10^{11}$ | independent clocks | with correction |
|---|---|---|---|---|---|
| 40 | 59,423 | 83,433 | 59,339,361 | 83,737,795 | 59,572,787 |
| 80 | 1,563 | 3,362 | 1,251,776 | 2,694,446 | 1,188,035 |
| 120 | 50 | 199 | 38,841 | 126,860 | 34,667 |
| 160 | 1 | 15.4 | 2,219 | 9,866 | 1,671 |
| 200 | 0 | 1.0 | 120 | 795 | 83 |
| 240 | 0 | 0.07 | 5 | 71 | 4.6 |
| 280 | 0 | 0.01 | 0 | 8.4 | 0.3 |
For single values the independent model is exact for $k=1,2,4$ and within 2% up to $k=18$, but it overestimates the tail: the events for different $k$ are not independent (a large prime clock can stop only one $k$ in the range, so failures are harder to stack). The ratio observed/independent on $n\le10^8$ is close to $\exp(0.138-0.01196K)$. This one-line correction, fitted only on $n\le10^8$, predicts the held-out range $10^8<n\le10^{11}$ within about 40% down to counts of a few (last column), and predicts the record $K\approx264$ for $n\le10^{11}$; the search gives 268.
Expected number of bad $n$ for #680 under the independent model (which overestimates): 0.89 in $[116,10^3)$, 0.086 in $[10^3,10^4)$, $7.6\cdot10^{-5}$ in $[10^4,10^5)$, $2\cdot10^{-13}$ in $[10^5,10^6)$, and it keeps falling: at $n=10^{11}$ there are about 158,000 admissible even $k$, each working with probability about 0.08, against a record of 268 needed so far. The model therefore predicts that $1,3,7,13,23,31,113,115$ is the complete list of positive bad $n$ for #680, in other words that #680 is true for all $n\ge116$. **Again a heuristic.**
## 4. Where I got stuck
- **No proof for large $n$.** For #680 one must show that for every large odd $n$ some even $k<\sqrt n$ has $n+k$ free of primes $\le k^2+1$. For $k\le n^{1/4}$ this is a sieve statement in an interval of length $n^{1/4}$ with sieving level up to $n^{1/2}$, far beyond what sieves give for every $n$ (they give almost all $n$). For $n^{1/4}<k<\sqrt n$ it asks for a prime in $(n,n+\sqrt n)$, which is open even under RH. What is proved is §1a; the missing step is stated there.
- **Almost all $n$** is now proved with a power saving (§1a); the full statement is not.
- **#681 beyond $10^{11}$** is sampled by windows, not searched exhaustively. The largest exception is not determined.
- **Dependence between $k$.** I measured it but did not derive the correction $\exp(-0.012K)$.
- Part (ii) of #680 (lower bound side with $e^{(1+\varepsilon)\sqrt k}$) is not treated.
- I read the problem pages and the Formal Conjectures files, not the original papers of Erdős and of Eggleton–Erdős–Selfridge.
## Lean source: `Erdos680.lean`
```lean
import Mathlib
/-!
# Erdős problem 680: the clock rule, the eight small exceptions, and a conditional reduction
`Good n` is the inner statement of `Erdos680.erdos_680.parts.i` in Formal Conjectures:
`∃ k ≠ 0, (n + k).minFac > k^2 + 1`. Nothing here proves the conjecture.
-/
namespace Erdos680
open Filter
/-- `n` is good when some `k ≠ 0` has least prime factor of `n + k` above `k^2 + 1`. -/
def Good (n : ℕ) : Prop := ∃ k ≠ 0, (n + k).minFac > k ^ 2 + 1
/-- The clock rule: for `m ≥ 2`, `minFac m > y` iff no prime clock `p ≤ y` divides `m`. -/
theorem minFac_gt_iff {m y : ℕ} (hm : 2 ≤ m) :
m.minFac > y ↔ ∀ p : ℕ, p.Prime → p ≤ y → ¬ p ∣ m := by
constructor
· intro h p hp hpy hdvd
have := Nat.minFac_le_of_dvd hp.two_le hdvd
omega
· intro h
by_contra hle
exact h m.minFac (Nat.minFac_prime (by omega)) (by omega) (Nat.minFac_dvd m)
/-- `k` works for `n` iff no clock `p ≤ k^2 + 1` shows `n ≡ -k (mod p)`. -/
theorem works_iff {n k : ℕ} (h : 2 ≤ n + k) :
(n + k).minFac > k ^ 2 + 1 ↔ ∀ p : ℕ, p.Prime → p ≤ k ^ 2 + 1 → ¬ p ∣ n + k :=
minFac_gt_iff h
/-- A `k` with `n + k ≤ k^2 + 1` never works. -/
theorem not_works_of_large {n k : ℕ} (hk : k ≠ 0) (h : n + k ≤ k ^ 2 + 1) :
¬ (n + k).minFac > k ^ 2 + 1 := by
have := Nat.minFac_le (n := n + k) (by omega)
omega
/-- Every even `n ≥ 2` is good, with `k = 1`. -/
theorem good_of_even {n : ℕ} (hn : Even n) (h2 : 2 ≤ n) : Good n := by
refine ⟨1, one_ne_zero, ?_⟩
have hodd : ¬ 2 ∣ n + 1 := by
obtain ⟨m, rfl⟩ := hn
omega
have hp := Nat.minFac_prime (n := n + 1) (by omega)
have hne : (n + 1).minFac ≠ 2 := fun h => hodd (h ▸ Nat.minFac_dvd (n + 1))
have := hp.two_le
norm_num
omega
/-- A prime `p > n` with `(p - n)^2 + 1 < p` makes `n` good. -/
theorem good_of_prime {n p : ℕ} (hp : p.Prime) (h1 : n < p) (h2 : (p - n) ^ 2 + 1 < p) : Good n := by
refine ⟨p - n, by omega, ?_⟩
have : n + (p - n) = p := by omega
rw [this, hp.minFac_eq]
exact h2
/-- Conditional reduction: if every large `n` is followed by a prime `p` with `(p - n)^2 + 1 < p`
(prime gaps below about `√p`), then the Formal Conjectures statement of part (i) holds. -/
theorem erdos_680_of_short_gaps
(H : ∀ᶠ (n : ℕ) in atTop, ∃ p : ℕ, p.Prime ∧ n < p ∧ (p - n) ^ 2 + 1 < p) :
∀ᶠ (n : ℕ) in atTop, ∃ k ≠ 0, (n + k).minFac > k ^ 2 + 1 := by
filter_upwards [H] with n hn
obtain ⟨p, hp, h1, h2⟩ := hn
exact good_of_prime hp h1 h2
/-- If `n` is bad, every prime `q > n` is far from `n`: `q ≤ (q - n)^2 + 1`. -/
theorem prime_far_of_bad {n q : ℕ} (h : ¬ Good n) (hq : q.Prime) (hn : n < q) : q ≤ (q - n) ^ 2 + 1 := by
by_contra hlt
exact h (good_of_prime hq hn (by omega))
/-- **Bad `n` lie in long prime gaps.** If `n` is bad and `p ≤ n < q` with `q` prime, then
`q ≤ (q - p)^2 + 1`, i.e. the gap `q - p` is at least `√(q - 1)`. -/
theorem long_gap_of_bad {n p q : ℕ} (h : ¬ Good n) (hq : q.Prime) (hpn : p ≤ n) (hn : n < q) :
q ≤ (q - p) ^ 2 + 1 := by
have h1 := prime_far_of_bad h hq hn
have h2 : (q - n) ^ 2 ≤ (q - p) ^ 2 := Nat.pow_le_pow_left (by omega) 2
omega
/-! ## Finite checks -/
/-- no `d` with `2 ≤ d ≤ y` divides `m` -/
def noDiv (m y : ℕ) : Bool := (List.range (y + 1)).all fun d => d < 2 || m % d != 0
/-- some `d` with `2 ≤ d ≤ y` divides `m` -/
def hasDiv (m y : ℕ) : Bool := (List.range (y + 1)).any fun d => 2 ≤ d && m % d == 0
/-- some `1 ≤ k ≤ K` works for `n` -/
def goodB (n K : ℕ) : Bool := (List.range (K + 1)).any fun k => k != 0 && noDiv (n + k) (k ^ 2 + 1)
/-- every `1 ≤ k < B` fails for `n` -/
def badB (n B : ℕ) : Bool := (List.range B).all fun k => k == 0 || hasDiv (n + k) (k ^ 2 + 1)
theorem minFac_gt_of_noDiv {m y : ℕ} (hm : 2 ≤ m) (h : noDiv m y = true) : m.minFac > y := by
rw [minFac_gt_iff hm]
intro p hp hpy hdvd
simp only [noDiv, List.all_eq_true, List.mem_range, Bool.or_eq_true, decide_eq_true_eq, bne_iff_ne] at h
rcases h p (by omega) with h | h
· have := hp.two_le
omega
· exact h (Nat.mod_eq_zero_of_dvd hdvd)
theorem minFac_le_of_hasDiv {m y : ℕ} (h : hasDiv m y = true) : m.minFac ≤ y := by
simp only [hasDiv, List.any_eq_true, List.mem_range, Bool.and_eq_true, decide_eq_true_eq, beq_iff_eq] at h
obtain ⟨d, hd, h2, hmod⟩ := h
have := Nat.minFac_le_of_dvd h2 (Nat.dvd_of_mod_eq_zero hmod)
omega
theorem good_of_goodB {n K : ℕ} (hn : 1 ≤ n) (h : goodB n K = true) : Good n := by
simp only [goodB, List.any_eq_true, List.mem_range, Bool.and_eq_true, bne_iff_ne] at h
obtain ⟨k, -, hk, hd⟩ := h
exact ⟨k, hk, minFac_gt_of_noDiv (by omega) hd⟩
theorem not_good_of_badB {n B : ℕ} (hB : n ≤ B * (B - 1)) (h : badB n B = true) : ¬ Good n := by
rintro ⟨k, hk, hgt⟩
simp only [badB, List.all_eq_true, List.mem_range, Bool.or_eq_true, beq_iff_eq] at h
by_cases hkB : k < B
· rcases h k hkB with h | h
· exact hk h
· have := minFac_le_of_hasDiv h
omega
· refine not_works_of_large hk ?_ hgt
have h1 : B * (B - 1) ≤ k * (k - 1) := Nat.mul_le_mul (by omega) (by omega)
have h2 : k * (k - 1) + k = k ^ 2 := by
cases k with
| zero => exact absurd rfl hk
| succ j => simp; ring
omega
/-- The eight positive integers found by the search with no admissible `k`. -/
theorem bad_1 : ¬ Good 1 := not_good_of_badB (B := 2) (by decide) (by decide +kernel)
theorem bad_3 : ¬ Good 3 := not_good_of_badB (B := 3) (by decide) (by decide +kernel)
theorem bad_7 : ¬ Good 7 := not_good_of_badB (B := 4) (by decide) (by decide +kernel)
theorem bad_13 : ¬ Good 13 := not_good_of_badB (B := 5) (by decide) (by decide +kernel)
theorem bad_23 : ¬ Good 23 := not_good_of_badB (B := 6) (by decide) (by decide +kernel)
theorem bad_31 : ¬ Good 31 := not_good_of_badB (B := 7) (by decide) (by decide +kernel)
theorem bad_113 : ¬ Good 113 := not_good_of_badB (B := 12) (by decide) (by decide +kernel)
theorem bad_115 : ¬ Good 115 := not_good_of_badB (B := 12) (by decide) (by decide +kernel)
/-- `0` is bad as well (trivially). -/
theorem bad_0 : ¬ Good 0 := not_good_of_badB (B := 1) (by decide) (by decide +kernel)
def exc (n : ℕ) : Bool := n == 0 || n == 1 || n == 3 || n == 7 || n == 13 || n == 23 || n == 31 || n == 113 || n == 115
def checkBelow (N K : ℕ) : Bool := (List.range N).all fun n => exc n || goodB n K
theorem good_of_checkBelow {N K n : ℕ} (h : checkBelow N K = true) (hn : n < N) (he : exc n = false) :
Good n := by
simp only [checkBelow, List.all_eq_true, List.mem_range, Bool.or_eq_true] at h
rcases h n hn with h | h
· simp [he] at h
· refine good_of_goodB ?_ h
rcases n with _ | n
· simp [exc] at he
· omega
theorem check_20000 : checkBelow 20000 60 = true := by decide +kernel
/-- Below 20000 the bad `n` are exactly `0, 1, 3, 7, 13, 23, 31, 113, 115`. -/
theorem good_below_20000 {n : ℕ} (hn : n < 20000) (he : exc n = false) : Good n :=
good_of_checkBelow check_20000 hn he
/-- 681: if `n + 1` is composite then `k = 1` works, so every bad `n` for 681 has `n + 1` prime. -/
theorem good681_of_succ_composite {n : ℕ} (h2 : 2 ≤ n + 1) (_h : ¬ (n + 1).Prime) :
∃ k > 0, ¬ (n + k).Prime ∧ 2 ≤ n + k ∧ (n + k).minFac > k ^ 2 := by
refine ⟨1, one_pos, _h, h2, ?_⟩
have := (Nat.minFac_prime (n := n + 1) (by omega)).two_le
simp only [one_pow]
omega
end Erdos680
#print axioms Erdos680.works_iff
#print axioms Erdos680.erdos_680_of_short_gaps
#print axioms Erdos680.long_gap_of_bad
#print axioms Erdos680.bad_115
#print axioms Erdos680.good_below_20000
#print axioms Erdos680.good_of_even
#print axioms Erdos680.good681_of_succ_composite
```