import Mathlib.NumberTheory.Divisors namespace Math.DivisorSequence /-- Cofactor trick for `k=3`: a proper divisor strictly greater than `n/3` must be `n/2`. More precisely, if `d ∈ n.properDivisors` and `n/3 < d`, then `d = n/2`. -/ theorem eq_div_two_of_mem_properDivisors_of_div_three_lt {n d : ℕ} (hd : d ∈ n.properDivisors) (h : n / 3 < d) : d = n / 2 := by classical have hn0 : n ≠ 0 := by intro hn0 subst hn0 simpa [Nat.properDivisors_zero] using hd -- write `n = d*k` with `k>1` rcases (Nat.mem_properDivisors_iff_exists (m := d) (n := n) hn0).1 hd with ⟨k, hk, hnk⟩ have hdpos : 0 < d := Nat.pos_of_mem_properDivisors hd -- from `n/3 < d` get `n < d*3` have hmul : n < d * 3 := (Nat.div_lt_iff_lt_mul (by decide : 0 < 3)).1 h -- rewrite using `n=d*k` have hmul' : d * k < d * 3 := by simpa [hnk, Nat.mul_assoc, Nat.mul_comm, Nat.mul_left_comm] using hmul have hklt3 : k < 3 := Nat.lt_of_mul_lt_mul_left hmul' have hk_le2 : k ≤ 2 := (Nat.lt_succ_iff).1 (by simpa using hklt3) have hk_ge2 : 2 ≤ k := (Nat.succ_le_iff).2 hk have hk2 : k = 2 := le_antisymm hk_le2 hk_ge2 -- conclude -- from `n=d*2`, `n/2 = d` have : n / 2 = d := by -- rewrite and simplify -- `Nat.mul_div_right` gives `(d*2)/2=d` simpa [hnk, hk2, Nat.mul_comm, Nat.mul_left_comm, Nat.mul_assoc] using (Nat.mul_div_right d 2) simpa [this] end Math.DivisorSequence