import Mathlib import LeanClassics.FibCubes /-! # A counterexample in Goel, *Sophie Germain Primes and the Totient of Fibonacci Numbers* Reference: arXiv:2604.17847v3 (22 Apr 2026). For an odd prime `q`, the paper defines `S(q)` as the set of residues `r mod π(q)` such that `q ∣ φ(F_m)` for every `m ≡ r (mod π(q))`, where `π(q)` is the Pisano period. The paper conjectures that `k = 2` in Theorem 4.2 (OQ2). It also states, for every odd prime `q ≤ 50000`, that `S(q) ≠ ∅` holds only for Sophie Germain primes `q`. Take `q = 2837` and `p = 761882591401 = 268552200 · 2837 + 1`. This file checks: * `p` and `q` are prime, and `2q + 1 = 5675` is not, so `q` is not a Sophie Germain prime; * `p ∣ F_258`; * `π(2837) = 5676 = 22 · 258`, that is, `5676` is the least positive `n` with `F_n ≡ 0` and `F_{n+1} ≡ 1 (mod 2837)`; * `0 ∈ S(2837)`, that is, `2837 ∣ φ(F_m)` whenever `5676 ∣ m`. So `p = kq + 1` with `z(p) ∣ π(q)` and `k = 268552200 ≠ 2`, and `S(2837) ≠ ∅` although `2837` is not a Sophie Germain prime. -/ namespace SophieGermainCounterexample open Nat theorem zmod_pow_eq_one_iff {p a n : ℕ} (hp : 1 < p) : ((a : ZMod p) ^ n = 1) ↔ a ^ n % p = 1 := by rw [← Nat.cast_pow, ← Nat.cast_one, ZMod.natCast_eq_natCast_iff', Nat.mod_eq_of_lt hp] theorem q_prime : Nat.Prime 2837 := by norm_num theorem not_sophie_germain : ¬ Nat.Prime (2 * 2837 + 1) := by norm_num /-- `p = 761882591401` is prime: a Lucas certificate with witness `17`. Here `p - 1 = 2³ · 3 · 5² · 7 · 43 · 1487 · 2837`. -/ theorem p_prime : Nat.Prime 761882591401 := by apply lucas_primality _ 17 · show (17 : ZMod 761882591401) ^ 761882591400 = 1 reduce_mod_char · intro l hl hdiv rw [show 761882591401 - 1 = 2 ^ 3 * 3 * 5 ^ 2 * 7 * 43 * 1487 * 2837 by norm_num] at hdiv simp only [hl.dvd_mul] at hdiv have e : ∀ r : ℕ, r.Prime → l ∣ r → l = r := fun r hr h => (Nat.prime_dvd_prime_iff_eq hl hr).1 h rcases hdiv with (((((h | h) | h) | h) | h) | h) | h · rw [e 2 Nat.prime_two (hl.dvd_of_dvd_pow h)] show (17 : ZMod 761882591401) ^ 380941295700 ≠ 1; reduce_mod_char; decide · rw [e 3 Nat.prime_three h] show (17 : ZMod 761882591401) ^ 253960863800 ≠ 1; reduce_mod_char; decide · rw [e 5 Nat.prime_five (hl.dvd_of_dvd_pow h)] show (17 : ZMod 761882591401) ^ 152376518280 ≠ 1; reduce_mod_char; decide · rw [e 7 (by norm_num) h] show (17 : ZMod 761882591401) ^ 108840370200 ≠ 1; reduce_mod_char; decide · rw [e 43 (by norm_num) h] show (17 : ZMod 761882591401) ^ 17718199800 ≠ 1; reduce_mod_char; decide · rw [e 1487 (by norm_num) h] show (17 : ZMod 761882591401) ^ 512362200 ≠ 1; reduce_mod_char; decide · rw [e 2837 q_prime h] show (17 : ZMod 761882591401) ^ 268552200 ≠ 1; reduce_mod_char; decide theorem p_eq : 761882591401 = 268552200 * 2837 + 1 := by norm_num theorem p_dvd_fib : 761882591401 ∣ fib 258 := by rw [Nat.dvd_iff_mod_eq_zero]; norm_num [Nat.fib_add_two] /-! ## The Pisano period of `2837` -/ /-- `n` is a period of the Fibonacci sequence modulo `q`. -/ def IsPer (q n : ℕ) : Prop := (fib n : ZMod q) = 0 ∧ (fib (n + 1) : ZMod q) = 1 theorem isPer_zero (q : ℕ) : IsPer q 0 := by simp [IsPer] theorem isPer_add_mul {q T : ℕ} (hT : IsPer q T) (j c : ℕ) : IsPer q (j + c * T) ↔ IsPer q j := by unfold IsPer rw [FibCubes.fib_add_mul_period hT.1 hT.2, show j + c * T + 1 = (j + 1) + c * T by ring, FibCubes.fib_add_mul_period hT.1 hT.2] theorem isPer_mod {q a b : ℕ} (hb : IsPer q b) : IsPer q a ↔ IsPer q (a % b) := by conv_lhs => rw [← Nat.mod_add_div a b, mul_comm] exact isPer_add_mul hb _ _ theorem isPer_gcd {q a b : ℕ} (ha : IsPer q a) (hb : IsPer q b) : IsPer q (Nat.gcd a b) := by induction a, b using Nat.gcd.induction with | H0 n => simpa using hb | H1 m n hm ih => rw [Nat.gcd_rec] exact ih ((isPer_mod ha).1 hb) ha theorem isPer_of_dvd {q T n : ℕ} (hT : IsPer q T) (h : T ∣ n) : IsPer q n := by obtain ⟨c, rfl⟩ := h have := (isPer_add_mul hT 0 c).2 (isPer_zero q) simpa [mul_comm] using this theorem natCast_zmod_eq {q a b : ℕ} (hb : b < q) : (a : ZMod q) = b ↔ a % q = b := by rw [ZMod.natCast_eq_natCast_iff', Nat.mod_eq_of_lt hb] theorem isPer_5676 : IsPer 2837 5676 := by constructor · have h : fib 5676 % 2837 = 0 := by norm_num [Nat.fib_add_two] exact (ZMod.natCast_eq_zero_iff _ _).2 (Nat.dvd_of_mod_eq_zero h) · have h : fib 5677 % 2837 = 1 := by norm_num [Nat.fib_add_two] have := (natCast_zmod_eq (q := 2837) (a := fib 5677) (b := 1) (by norm_num)).2 h rw [Nat.cast_one] at this; exact this theorem not_isPer_2838 : ¬ IsPer 2837 2838 := by rintro ⟨-, h⟩ have h' : fib 2839 % 2837 = 1 := (natCast_zmod_eq (q := 2837) (a := fib 2839) (b := 1) (by norm_num)).1 (by rw [Nat.cast_one]; exact h) norm_num [Nat.fib_add_two] at h' theorem not_isPer_1892 : ¬ IsPer 2837 1892 := by rintro ⟨h, -⟩ have h' : fib 1892 % 2837 = 0 := Nat.mod_eq_zero_of_dvd ((ZMod.natCast_eq_zero_iff _ _).1 h) norm_num [Nat.fib_add_two] at h' theorem not_isPer_516 : ¬ IsPer 2837 516 := by rintro ⟨h, -⟩ have h' : fib 516 % 2837 = 0 := Nat.mod_eq_zero_of_dvd ((ZMod.natCast_eq_zero_iff _ _).1 h) norm_num [Nat.fib_add_two] at h' theorem not_isPer_132 : ¬ IsPer 2837 132 := by rintro ⟨h, -⟩ have h' : fib 132 % 2837 = 0 := Nat.mod_eq_zero_of_dvd ((ZMod.natCast_eq_zero_iff _ _).1 h) norm_num [Nat.fib_add_two] at h' /-- **`π(2837) = 5676`.** `5676` is a period, and no smaller positive `n` is. -/ theorem pisano_2837 : IsPer 2837 5676 ∧ ∀ n, 0 < n → n < 5676 → ¬ IsPer 2837 n := by refine ⟨isPer_5676, fun n hn0 hn h => ?_⟩ have hg := isPer_gcd h isPer_5676 set g := Nat.gcd n 5676 have hg0 : 0 < g := Nat.gcd_pos_of_pos_left _ hn0 have hgle : g < 5676 := lt_of_le_of_lt (Nat.gcd_le_left _ hn0) hn have key : ∀ d, d ∣ 5676 → d < 5676 → d ∣ 2838 ∨ d ∣ 1892 ∨ d ∣ 516 ∨ d ∣ 132 := by intro d hd hlt obtain ⟨c, hc⟩ := hd have hc1 : c ≠ 1 := by rintro rfl; omega obtain ⟨l, hl, hlc⟩ := Nat.exists_prime_and_dvd hc1 have hl5676 : l ∣ 5676 := by rw [hc]; exact Dvd.dvd.mul_left hlc d have hdl : d * l ∣ 5676 := by rw [hc]; exact Nat.mul_dvd_mul_left d hlc rw [show (5676 : ℕ) = 2 ^ 2 * 3 * 11 * 43 by norm_num] at hl5676 simp only [hl.dvd_mul] at hl5676 have e : ∀ r : ℕ, r.Prime → l ∣ r → l = r := fun r hr h => (Nat.prime_dvd_prime_iff_eq hl hr).1 h rcases hl5676 with ((h | h) | h) | h · rw [e 2 Nat.prime_two (hl.dvd_of_dvd_pow h)] at hdl left; exact (Nat.dvd_div_of_mul_dvd (by rwa [mul_comm] at hdl) : d ∣ 5676 / 2) · rw [e 3 Nat.prime_three h] at hdl right; left; exact (Nat.dvd_div_of_mul_dvd (by rwa [mul_comm] at hdl) : d ∣ 5676 / 3) · rw [e 11 (by norm_num) h] at hdl right; right; left; exact (Nat.dvd_div_of_mul_dvd (by rwa [mul_comm] at hdl) : d ∣ 5676 / 11) · rw [e 43 (by norm_num) h] at hdl right; right; right; exact (Nat.dvd_div_of_mul_dvd (by rwa [mul_comm] at hdl) : d ∣ 5676 / 43) rcases key g (Nat.gcd_dvd_right _ _) hgle with h1 | h1 | h1 | h1 · exact not_isPer_2838 (isPer_of_dvd hg h1) · exact not_isPer_1892 (isPer_of_dvd hg h1) · exact not_isPer_516 (isPer_of_dvd hg h1) · exact not_isPer_132 (isPer_of_dvd hg h1) /-- **`0 ∈ S(2837)`.** If `π(2837) = 5676` divides `m`, then `2837 ∣ φ(F_m)`. -/ theorem zero_mem_S (m : ℕ) (hm : 5676 ∣ m) : 2837 ∣ Nat.totient (fib m) := by have h258 : 258 ∣ m := dvd_trans (by norm_num) hm have hp : 761882591401 ∣ fib m := dvd_trans p_dvd_fib (Nat.fib_dvd _ _ h258) have htot : Nat.totient 761882591401 ∣ Nat.totient (fib m) := Nat.totient_dvd_of_dvd hp rw [Nat.totient_prime p_prime] at htot exact dvd_trans ⟨268552200, by norm_num⟩ htot /-- **Summary.** `q = 2837` is prime but not a Sophie Germain prime. Its Pisano period is `5676`, and `S(2837) ∋ 0`. The prime `p = 268552200 · q + 1` satisfies `p ∣ F_258` with `258 ∣ π(q)`, so the rank of apparition `z(p)` divides `π(q)`, yet `k = 268552200 ≠ 2`. -/ theorem counterexample : Nat.Prime 2837 ∧ ¬ Nat.Prime (2 * 2837 + 1) ∧ Nat.Prime 761882591401 ∧ 761882591401 = 268552200 * 2837 + 1 ∧ 761882591401 ∣ fib 258 ∧ 258 ∣ 5676 ∧ (IsPer 2837 5676 ∧ ∀ n, 0 < n → n < 5676 → ¬ IsPer 2837 n) ∧ (∀ m, 5676 ∣ m → 2837 ∣ Nat.totient (fib m)) := ⟨q_prime, not_sophie_germain, p_prime, p_eq, p_dvd_fib, by norm_num, pisano_2837, zero_mem_S⟩ end SophieGermainCounterexample