Lean / DevSingh05/oeis-a346149 / A346149.lean
Lean reader

A346149.lean

96 lines10 declarationsno sorryimports Mathlib
  1. import Mathlib
  2. /-!
  3. # A counterexample to a conjecture in OEIS A346149
  4. A346149: `a(n)` is the least `k > 1` such that `n ^ k + n + 1` is prime, or `0` if there is
  5. no such `k`. It was conjectured that `a(n) > 0` whenever `n ≢ 1 (mod 3)`.
  6. We show that `n = 243779134570275685188` (which is `≡ 0 (mod 3)`) is a counterexample:
  7. `n ^ k + n + 1` is composite for every `k > 1`. The proof is a covering argument.
  8. * If `k ≡ 2 (mod 3)` then `n ^ 2 + n + 1 ∣ n ^ k + n + 1`, because `n ^ 3 ≡ 1` modulo
  9. `n ^ 2 + n + 1`. For `k > 2` this is a proper divisor; for `k = 2` the number
  10. `n ^ 2 + n + 1` itself is divisible by `43`.
  11. * Otherwise `k` lies in one of eleven residue classes `k ≡ r (mod o)`, each of which comes
  12. with a small prime `p` such that `n ^ o ≡ 1 (mod p)` and `p ∣ n ^ r + n + 1`, so that
  13. `p ∣ n ^ k + n + 1`. These classes cover all residues modulo `180` not `≡ 2 (mod 3)`.
  14. -/
  15. namespace A346149
  16. /-! ### General lemmas -/
  17. /-- If `n ^ o ≡ 1 (mod p)` and `p ∣ n ^ r + n + 1`, then `p ∣ n ^ k + n + 1` for every
  18. `k = r + o * t` in the residue class of `r` modulo `o`. -/
  19. theorem dvd_of_period {n p o r : ℕ} (ho : n ^ o ≡ 1 [MOD p]) (hr : p ∣ n ^ r + n + 1) (t : ℕ) :
  20. p ∣ n ^ (r + o * t) + n + 1 := by
  21. have h : n ^ (r + o * t) ≡ n ^ r [MOD p] := by
  22. simpa [pow_add, pow_mul] using (ho.pow t).mul_left (n ^ r)
  23. exact (Nat.modEq_zero_iff_dvd.mp
  24. (((h.add_right n).add_right 1).trans (Nat.modEq_zero_iff_dvd.mpr hr)))
  25. /-- `n ^ 3 ≡ 1` modulo `n ^ 2 + n + 1`, since `n ^ 3 + (n ^ 2 + n + 1) = 1 + (n ^ 2 + n + 1) * n`. -/
  26. theorem cube_modEq_one (n : ℕ) : n ^ 3 ≡ 1 [MOD n ^ 2 + n + 1] := by
  27. unfold Nat.ModEq
  28. rw [← Nat.add_mod_right (n ^ 3), show n ^ 3 + (n ^ 2 + n + 1) = 1 + (n ^ 2 + n + 1) * n by ring,
  29. Nat.add_mul_mod_self_left]
  30. /-- `n ^ 2 + n + 1` divides `n ^ k + n + 1` whenever `k ≡ 2 (mod 3)`. -/
  31. theorem sq_add_dvd (n t : ℕ) : n ^ 2 + n + 1 ∣ n ^ (2 + 3 * t) + n + 1 :=
  32. dvd_of_period (cube_modEq_one n) dvd_rfl t
  33. /-! ### The counterexample -/
  34. /-- The counterexample. -/
  35. abbrev n : ℕ := 243779134570275685188
  36. /-- The covering system: triples `(p, r, o)` with `n ^ o ≡ 1 (mod p)` and `p ∣ n ^ r + n + 1`,
  37. so that `p ∣ n ^ k + n + 1` whenever `k ≡ r (mod o)`. -/
  38. def cover : List (ℕ × ℕ × ℕ) :=
  39. [(5, 0, 4), (7, 1, 6), (11, 1, 5), (13, 10, 12), (19, 0, 9), (31, 9, 15), (37, 3, 18),
  40. (331, 0, 15), (757, 30, 36), (3511, 33, 45), (9091, 42, 45)]
  41. /-- Each triple `(p, r, o)` of `cover` has the stated properties (and `1 < p < n`, `o ∣ 180`). -/
  42. theorem cover_spec : ∀ e ∈ cover, 2 ≤ e.1 ∧ e.1 < n ∧ e.2.2 ∣ 180 ∧
  43. n ^ e.2.2 ≡ 1 [MOD e.1] ∧ e.1 ∣ n ^ e.2.1 + n + 1 := by
  44. decide +kernel
  45. /-- The classes `r mod o` of `cover` contain every residue modulo `180` that is not
  46. `≡ 2 (mod 3)`. -/
  47. theorem cover_complete : ∀ j < 180, j % 3 = 2 ∨ ∃ e ∈ cover, j % e.2.2 = e.2.1 := by
  48. decide +kernel
  49. /-- The case `k = 2`: `43` divides `n ^ 2 + n + 1`. -/
  50. theorem fortythree_dvd : 43 ∣ n ^ 2 + n + 1 := by decide +kernel
  51. /-- `n ^ k + n + 1` is composite for every `k > 1`. -/
  52. theorem not_prime (k : ℕ) (hk : 1 < k) : ¬ Nat.Prime (n ^ k + n + 1) := by
  53. have hbig : n < n ^ k + n + 1 := by omega
  54. rcases cover_complete (k % 180) (Nat.mod_lt _ (by norm_num)) with h3 | ⟨e, he, hr⟩
  55. · -- `k ≡ 2 (mod 3)`
  56. rw [Nat.mod_mod_of_dvd k (by norm_num : 3 ∣ 180)] at h3
  57. obtain ⟨t, rfl⟩ : ∃ t, k = 2 + 3 * t := ⟨k / 3, by omega⟩
  58. rcases Nat.eq_zero_or_pos t with rfl | ht
  59. · exact Nat.not_prime_of_dvd_of_lt fortythree_dvd (by norm_num) (by norm_num)
  60. · refine Nat.not_prime_of_dvd_of_lt (sq_add_dvd n t) (by norm_num) ?_
  61. have : n ^ 2 < n ^ (2 + 3 * t) := Nat.pow_lt_pow_right (by norm_num) (by omega)
  62. omega
  63. · -- `k ≡ r (mod o)` for some `(p, r, o)` in the covering system
  64. obtain ⟨hp2, hpn, ho180, ho, hdvd⟩ := cover_spec e he
  65. rw [Nat.mod_mod_of_dvd k ho180] at hr
  66. have hk' : k = e.2.1 + e.2.2 * (k / e.2.2) := by rw [← hr, Nat.mod_add_div]
  67. rw [hk'] at hbig ⊢
  68. exact Nat.not_prime_of_dvd_of_lt (dvd_of_period ho hdvd _) hp2 (hpn.trans hbig)
  69. end A346149
  70. /-- **Counterexample to the conjecture in OEIS A346149.** The number
  71. `n = 243779134570275685188` is not `≡ 1 (mod 3)`, yet `n ^ k + n + 1` is composite for
  72. every `k > 1`. -/
  73. theorem a346149_counterexample : (243779134570275685188 : ℕ) % 3 ≠ 1 ∧
  74. ∀ k : ℕ, 1 < k → ¬ Nat.Prime (243779134570275685188 ^ k + 243779134570275685188 + 1) :=
  75. ⟨by norm_num, A346149.not_prime⟩
  76. #print axioms a346149_counterexample