{
  "id": "1997",
  "ident": "NS.01997",
  "slug": "erdos-399",
  "title": "Erdős Problem 399",
  "status": "solved",
  "statement_status": "reviewed",
  "statement_md": "Is it true that there are no solutions to `n! = x^k ± y^k` with `x,y,n ∈ ℕ`, `x*y > 1`, and\n`k > 2`?\n\nThe answer is no: Jonas Barfield found the counterexample `10! = 48^4 - 36^4` (equivalently,\n`10! + 36^4 = 48^4`).\n\nThis is discussed in problem D2 of Guy's collection [Gu04].\n\nThis was formalized in Lean by Lu using Codex.",
  "subjects": [
    "math.NT",
    "msc:11"
  ],
  "tags": [
    "question"
  ],
  "collection": "erdos",
  "source_url": null,
  "solved_on_platform": false,
  "needs_answer": false,
  "version": 1,
  "decl_name": "Erdos399.erdos_399",
  "statement_lean": "theorem erdos_399 :\n    ∃ (n x y k : ℕ), 1 < x * y ∧ 2 < k ∧ (n ! = x ^ k + y ^ k ∨ n ! + y ^ k = x ^ k)",
  "challenge_source": "/-\nCopyright 2026 The Formal Conjectures Authors.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    https://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n-/\nmodule\n\npublic import FormalConjecturesUtil\n\n/-!\n# Erdős Problem 399\n\nIs it true that there are no solutions to $n! = x^k \\pm y^k$ with $x,y,n \\in \\mathbb{N}$,\nwith $xy > 1$ and $k > 2$?\n\n*References:*\n - [erdosproblems.com/399](https://www.erdosproblems.com/399)\n- [Br32] Breusch, Robert, Zur Verallgemeinerung des Bertrandschen Postulates, da\\ss zwischen $x$\n  und 2 $x$ stets Primzahlen liegen. Math. Z. (1932), 505--526.\n- [ErOb37] Erdős, P. and Obláth, R., \\\"Über diophantische Gleichungen der Form $n!=x^p+y^p$ und\n  $n!\\pm m!=x^p$. Acta Litt. ac Sci. Reg. Univ. Hung. Fr.-Jos., Sect. Sci. Math. (1937), 241-255.\n- [Gu04] Guy, Richard K., Unsolved problems in number theory. (2004), xviii+437.\n- [PoSh73] Pollack, Richard M. and Shapiro, Harold N., The next to last case of a factorial\n  diophantine equation. Comm. Pure Appl. Math. (1973), 313-325.\n-/\n\n@[expose] public section\n\nopen Nat\n\nnamespace Erdos399\n\n/--\nIs it true that there are no solutions to `n! = x^k ± y^k` with `x,y,n ∈ ℕ`, `x*y > 1`, and\n`k > 2`?\n\nThe answer is no: Jonas Barfield found the counterexample `10! = 48^4 - 36^4` (equivalently,\n`10! + 36^4 = 48^4`).\n\nThis is discussed in problem D2 of Guy's collection [Gu04].\n\nThis was formalized in Lean by Lu using Codex.\n-/\n@[category research solved, question, AMS 11]\ntheorem erdos_399 :\n    ∃ (n x y k : ℕ), 1 < x * y ∧ 2 < k ∧ (n ! = x ^ k + y ^ k ∨ n ! + y ^ k = x ^ k) := by\n  exact ⟨10, 48, 36, 4, by decide⟩\n\n/-- Erdős and Obláth [ErOb37] proved this is true when $(x,y)=1$ and $k\\neq 4$. -/\n@[category research solved, AMS 11]\ntheorem erdos_399.variants.erdos_oblath {n x y k : ℕ} :\n    x.Coprime y → 1 < x * y → 2 < k → k ≠ 4 →\n      n ! ≠ x ^ k + y ^ k ∧ n ! + y ^ k ≠ x ^ k := by\n  sorry\n\n/-- Pollack and Shapiro [PoSh73] proved there are no solutions to $n!=x^4-1$. -/\n@[category research solved, AMS 11]\ntheorem erdos_399.variants.pollack_shapiro (n x : ℕ) : n ! + 1 ≠ x ^ 4 := by\n  sorry\n\n/--\nCambie has also observed that considerations modulo $8$ rule out any solutions to $n!=x^4+y^4$ with\n$(x,y)=1$ and $xy>1$.\n-/\n@[category research solved, AMS 11]\ntheorem erdos_399.variants.cambie {n x y : ℕ} :\n    x.Coprime y → 1 < x * y → n ! ≠ x ^ 4 + y ^ 4 := by\n  intro hxy h1 heq\n  rcases Nat.lt_or_ge n 4 with hn | hn\n  · -- n ≤ 3: n! ≤ 6, but x*y > 1 forces max x y ≥ 2, so x^4 + y^4 ≥ 16.\n    have hfact_le : n ! ≤ 6 := by\n      interval_cases n <;> decide\n    have hxy2 : 2 ≤ x ∨ 2 ≤ y := by\n      by_contra hc\n      simp only [not_or, not_le] at hc\n      obtain ⟨hx, hy⟩ := hc\n      interval_cases x <;> interval_cases y <;> omega\n    have hbig : 16 ≤ x ^ 4 + y ^ 4 := by\n      rcases hxy2 with hx | hy\n      · have h16 : (2 : ℕ) ^ 4 ≤ x ^ 4 := Nat.pow_le_pow_left hx 4\n        omega\n      · have h16 : (2 : ℕ) ^ 4 ≤ y ^ 4 := Nat.pow_le_pow_left hy 4\n        omega\n    omega\n  · -- 4 ≤ n: 8 ∣ n!, but coprimality ⇒ not both even ⇒ (x^4 + y^4) % 8 ∈ {1,2}.\n    have h4le : (4 : ℕ) ! ∣ n ! := Nat.factorial_dvd_factorial hn\n    have h8 : (8 : ℕ) ∣ n ! := dvd_trans (by decide) h4le\n    have h8' : (8 : ℕ) ∣ (x ^ 4 + y ^ 4) := by rw [← heq]; exact h8\n    have hnotboth2 : x % 2 = 1 ∨ y % 2 = 1 := by\n      by_contra hc\n      simp only [not_or] at hc\n      obtain ⟨hx0, hy0⟩ := hc\n      have hx0' : x % 2 = 0 := by omega\n      have hy0' : y % 2 = 0 := by omega\n      have hx2 : (2 : ℕ) ∣ x := Nat.dvd_of_mod_eq_zero hx0'\n      have hy2 : (2 : ℕ) ∣ y := Nat.dvd_of_mod_eq_zero hy0'\n      have hg : (2 : ℕ) ∣ Nat.gcd x y := Nat.dvd_gcd hx2 hy2\n      rw [(hxy : Nat.gcd x y = 1)] at hg\n      norm_num at hg\n    have parity4 : ∀ z : ℕ, z ^ 4 % 8 = z % 2 := by\n      intro z\n      rcases Nat.even_or_odd z with ⟨k, hk⟩ | ⟨k, hk⟩\n      · subst hk\n        have heqz : (k + k) ^ 4 = 8 * (2 * k ^ 4) := by ring\n        rw [heqz]; omega\n      · subst hk\n        have heqz : (2 * k + 1) ^ 4 = 8 * (2 * k ^ 4 + 4 * k ^ 3 + 3 * k ^ 2 + k) + 1 := by ring\n        rw [heqz]; omega\n    have hx4 := parity4 x\n    have hy4 := parity4 y\n    omega\n\n/--\nErdős and Obláth observed that the Bertrand-style fact (first proved by Breusch [Br32]) that, if\n$q_i$ is the sequence of primes congruent to $3\\pmod{4}$ then $q_{i+1}<2q_i$ except for $q_1=3$,\ntogether with Fermat's theorem on the sums of two squares implies that the only solution to\n$n!=x^2+y^2$ is $6!=12^2+24^2$.\n-/\n@[category research solved, AMS 11]\ntheorem erdos_399.variants.sum_two_squares :\n    ∀ {n x y : ℕ}, 1 < x * y → n ! = x ^ 2 + y ^ 2 →\n      n = 6 ∧ (x = 12 ∧ y = 24 ∨ x = 24 ∧ y = 12) := by\n  sorry\n\nend Erdos399\n",
  "statement_hash": "fe5ffef04284e52d044219044ec4027d0824746bbd6b6698ad1da1d4fc908aff",
  "toolchain": "leanprover/lean4:v4.33.1",
  "upstream_commit": "f9b3868d5ca994a7bf95039bcec05338c0c21e2f",
  "workspace": "formal-conjectures",
  "field": "math",
  "formalization": "formal",
  "verification": "lean-kernel",
  "license": "Apache-2.0",
  "attribution": "google-deepmind/formal-conjectures contributors",
  "metric_name": null,
  "metric_direction": null,
  "critiques": [],
  "public_partial_proofs": [],
  "research_threads": [],
  "instructions": "Read research_threads first: other people's public repositories and what they already tried. Write Solution.lean starting from challenge_source. Keep every definition identical, prove decl_name with exactly the same type, no sorry in its dependency closure, no new axioms, no native_decide, no metaprogramming. Submit with POST /api/v1/submissions."
}