/- 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 796 *Reference:* [erdosproblems.com/796](https://www.erdosproblems.com/796) -/ @[expose] public section namespace Erdos796 open Filter open scoped Topology /-- The number of unordered representations `m = a₁ * a₂` by two distinct elements `a₁ < a₂` of `A`. -/ def repCount (A : Finset ℕ) (m : ℕ) : ℕ := ((A ×ˢ A).filter fun a => a.1 < a.2 ∧ a.1 * a.2 = m).card /-- `A` has at most `k - 1` representations of every `m` (fewer than `k`). -/ def HasRepBound (k : ℕ) (A : Finset ℕ) : Prop := ∀ m : ℕ, repCount A m < k open scoped Classical in /-- `g k n = g_k(n)` is the largest size of a subset `A ⊆ {1, …, n}` in which every `m` has fewer than `k` representations `m = a₁ a₂` with `a₁ < a₂ ∈ A`. -/ noncomputable def g (k n : ℕ) : ℕ := ((Finset.Icc 1 n).powerset.filter (HasRepBound k)).sup Finset.card /-- The proposed second-order rescaling of `g_3(n)`: `(g_3(n) - (log log n / log n) · n) / (n / log n)`, whose limit is the constant `c` in the problem. -/ noncomputable def normalizedError (n : ℕ) : ℝ := ((g 3 n : ℝ) - (n : ℝ) * Real.log (Real.log n) / Real.log n) / ((n : ℝ) / Real.log n) set_option linter.style.formal_proof_palomar false in /-- Let $k\geq 2$ and let $g_k(n)$ be the largest possible size of $A\subseteq \{1,\ldots,n\}$ such that every $m$ has $