/- 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 1058 *References:* - [erdosproblems.com/1058](https://www.erdosproblems.com/1058) - [Gu04] Guy, Richard K., *Unsolved problems in number theory*. (2004), xviii+437. - [Lu01] Luca, Florian, *On a conjecture of Erdős and Stewart*. Math. Comp. (2001), 893-896. -/ @[expose] public section open Nat namespace Erdos1058 /-- `n` is a *solution* if `n ∈ [p_{k-1}, p_k)` for some `k` (with the convention `p_0 = 1`, where `p_1 = 2 < p_2 < ⋯` are the primes) and the only primes dividing `n! + 1` are `p_k` and `p_{k+1}`. Primes are indexed from `0` by `Nat.nth Nat.Prime`. -/ def IsSolution (n : ℕ) : Prop := 0 < n ∧ ∃ k : ℕ, (if k = 0 then 1 else nth Nat.Prime (k - 1)) ≤ n ∧ n < nth Nat.Prime k ∧ ∀ r : ℕ, r.Prime → r ∣ n ! + 1 → r = nth Nat.Prime k ∨ r = nth Nat.Prime (k + 1) set_option linter.style.formal_proof_palomar false in /-- Let $2=p_1