import Mathlibnamespace Erdos311Digits/-- The arithmetic digit used in the constructive fractional-part theorem. Scaling by p^kleaves a nonzero digit that one denominator p^a*t realizes without changing earlier digits. -/theorem one_digit {p : ℕ} [Fact p.Prime] (a k c : ℕ) (hc : ¬p ∣ c)(covers : ∀ t : ℕ, 0 < t → t < p → t ∣ c) (digit : ZMod p) (hd : digit ≠ 0) :∃ t : ℕ, 0 < t ∧ t < p ∧ (↑(c/t) : ZMod p) = digit ∧(p^(a+k)*c)/(p^a*t) = p^k*(c/t) := byhave hcp : (c : ZMod p) ≠ 0 := fun h => hc ((ZMod.natCast_eq_zero_iff ..).mp h)let x : ZMod p := (c : ZMod p)/digithave hx : x ≠ 0 := div_ne_zero hcp hdlet t := x.valhave ht : (t : ZMod p) = x := ZMod.natCast_zmod_val xhave htn : 0 < t := byby_contra! hhave ht0 : t = 0 := by omegaexact hx (by simpa [ht0] using ht.symm)have hp0 : 0 < p := (Fact.out : Nat.Prime p).poshave hlt : t < p := x.val_lthave he : c/t*t = c := Nat.div_mul_cancel (covers t htn hlt)refine ⟨t, htn, hlt, ?_, ?_⟩· apply mul_right_cancel₀ (show (t : ZMod p) ≠ 0 by rwa [ht])calc (↑(c/t) : ZMod p)*t = (c : ZMod p) := by rw [← Nat.cast_mul,he]_ = digit*t := by rw [ht]; dsimp [x]; field_simp· apply Nat.div_eq_of_eq_mul_right (Nat.mul_pos (pow_pos hp0 _) htn)rw [pow_add]calc p^a*p^k*c = p^a*p^k*(c/t*t) := by rw [he]_ = _ := by ring/-- The factor left after removing the full p-power in an lcm contains every positive t<p. -/theorem small_divisors_in_unit (N p e c : ℕ) (hp : p.Prime) (hpN : p ≤ N)(hL : (Finset.Icc 1 N).lcm id = p^e*c) : ∀ t : ℕ, 0 < t → t < p → t ∣ c := byintro t ht htphave hn : ¬p ∣ t := fun h => (not_le_of_gt htp) (Nat.le_of_dvd ht h)have hd : t ∣ (Finset.Icc 1 N).lcm id := Finset.dvd_lcm (f := id) (Finset.mem_Icc.mpr ⟨ht,by omega⟩)rw [hL] at hdexact ((hp.coprime_iff_not_dvd.mpr hn).pow_left e).symm.dvd_of_dvd_mul_left hd/-- Fixing one signed base-p digit increases the power dividing the residual. -/theorem lift_power {p : ℕ} (k : ℕ) (residualValue nextWeight digitValue : ℤ)(hvalue : residualValue = (p : ℤ)^k * digitValue)(digitWeight : ℤ) (hweight : nextWeight = (p : ℤ)^k * digitWeight)(hmatch : (p : ℤ) ∣ digitValue-digitWeight) :(p : ℤ)^(k+1) ∣ residualValue-nextWeight := byobtain ⟨d,hd⟩ := hmatchrefine ⟨d,?_⟩rw [hvalue,hweight,← mul_sub,hd,pow_succ]ring#print axioms small_divisors_in_unit#print axioms lift_power#print axioms one_digitend Erdos311Digits