|
| 1 | +/- |
| 2 | +Copyright (c) 2025 Jeremy Tan. All rights reserved. |
| 3 | +Released under Apache 2.0 license as described in the file LICENSE. |
| 4 | +Authors: Jeremy Tan |
| 5 | +-/ |
| 6 | +import Mathlib.Algebra.BigOperators.Intervals |
| 7 | +import Mathlib.Data.Int.Interval |
| 8 | +import Mathlib.GroupTheory.Perm.Fin |
| 9 | + |
| 10 | +/-! |
| 11 | +# IMO 2001 Q4 |
| 12 | +
|
| 13 | +Let $n > 1$ be an odd integer and let $c_1, c_2, \dots, c_n$ be integers. For each permutation |
| 14 | +$a = (a_1, a_2, \dots, a_n)$ of $\{1, 2, \dots, n\}$, define $S(a) = \sum_{i=1}^n c_i a_i$. |
| 15 | +Prove that there exist two permutations $a ≠ b$ of $\{1, 2, \dots, n\}$ such that |
| 16 | +$n!$ is a divisor of $S(a) - S(b)$. |
| 17 | +
|
| 18 | +# Solution |
| 19 | +
|
| 20 | +Suppose for contradiction that all the $S(a)$ have distinct residues modulo $n!$, then |
| 21 | +$$\sum_{i=0}^{n!-1} i ≡ \sum_a S(a) = \sum_i c_i \sum_a a_i = (n-1)! \frac{n(n+1)}2 \sum_i c_i$$ |
| 22 | +$$= n! \frac{n+1}2 \sum_i c_i ≡ 0 \bmod n$$ |
| 23 | +where the last equality relies on $n$ being odd. But $\sum_{i=0}^{n!-1} i = \frac{n!(n!-1)}2$ |
| 24 | +is not divisible by $n!$, since the quotient is $\frac{n!-1}2$ and $n!$ is even when $n > 1$. |
| 25 | +-/ |
| 26 | + |
| 27 | +namespace Imo2001Q4 |
| 28 | + |
| 29 | +open Equiv Finset |
| 30 | +open scoped Nat |
| 31 | + |
| 32 | +variable {n : ℕ} {c : Fin n → ℤ} |
| 33 | + |
| 34 | +/-- The function `S` in the problem. As implemented here it accepts a permutation of `Fin n` |
| 35 | +rather than `Icc 1 n`, and as such contains `+ 1` to compensate. -/ |
| 36 | +def S (c : Fin n → ℤ) (a : Perm (Fin n)) : ℤ := ∑ i, c i * (a i + 1) |
| 37 | + |
| 38 | +/-- Assuming the opposite of what is to be proved, the sum of `S` over all permutations is |
| 39 | +congruent to the sum of all residues modulo `n!`, i.e. `n! * (n! - 1) / 2`. -/ |
| 40 | +lemma sum_range_modEq_sum_of_contra (hS : ¬∃ a b, a ≠ b ∧ (n ! : ℤ) ∣ S c a - S c b) : |
| 41 | + n ! * ((n ! : ℤ) - 1) / 2 ≡ ∑ a, S c a [ZMOD n !] := by |
| 42 | + have mir : ∀ a, S c a % n ! ∈ Ico (0 : ℤ) n ! := fun a ↦ by |
| 43 | + rw [mem_Ico]; constructor |
| 44 | + · exact Int.emod_nonneg _ (by positivity) |
| 45 | + · exact Int.emod_lt_of_pos _ (by positivity) |
| 46 | + let f : Perm (Fin n) → Ico (0 : ℤ) n ! := fun a ↦ ⟨_, mir a⟩ |
| 47 | + have bijf : Function.Bijective f := by |
| 48 | + rw [Fintype.bijective_iff_injective_and_card, Fintype.card_coe, Int.card_Ico, sub_zero, |
| 49 | + Int.toNat_natCast, Fintype.card_perm, Fintype.card_fin]; refine ⟨?_, rfl⟩ |
| 50 | + contrapose! hS; unfold Function.Injective at hS; push_neg at hS; obtain ⟨a, b, he, hn⟩ := hS |
| 51 | + use a, b, hn; simp only [f, Subtype.mk.injEq] at he; exact Int.ModEq.dvd he.symm |
| 52 | + let e : Perm (Fin n) ≃ Ico (0 : ℤ) n ! := ofBijective _ bijf |
| 53 | + change _ % _ = _ % _; rw [sum_int_mod]; congr 1 |
| 54 | + change _ = ∑ i, (e i).1; rw [Equiv.sum_comp] |
| 55 | + change _ = ∑ i : { x // x ∈ _ }, id i.1; simp_rw [sum_coe_sort, id_eq] |
| 56 | + have Ico_eq : Ico (0 : ℤ) n ! = (range n !).map ⟨_, Nat.cast_injective⟩ := by |
| 57 | + ext i |
| 58 | + simp_rw [mem_Ico, mem_map, mem_range, Function.Embedding.coeFn_mk] |
| 59 | + constructor <;> intro h |
| 60 | + · lift i to ℕ using h.1; rw [Nat.cast_lt] at h; simp [h.2] |
| 61 | + · obtain ⟨z, lz, rfl⟩ := h; simp [lz] |
| 62 | + rw [Ico_eq, sum_map, Function.Embedding.coeFn_mk, ← Nat.cast_sum, sum_range_id] |
| 63 | + change _ = ((_ : ℕ) : ℤ) / (2 : ℕ) |
| 64 | + rw [Nat.cast_mul, Nat.cast_ofNat, Nat.cast_pred (Nat.factorial_pos n)] |
| 65 | + |
| 66 | +/-- The sum over all permutations of `Icc 1 n` of the entry at any fixed position is |
| 67 | +`(n - 1)! * (n * (n + 1) / 2)`. -/ |
| 68 | +lemma sum_perm_add_one {i : Fin n} (hn : 1 ≤ n) : |
| 69 | + ∑ a : Perm (Fin n), ((a i).1 + 1) = (n - 1)! * (n * (n + 1) / 2) := by |
| 70 | + rw [le_iff_exists_add'] at hn; obtain ⟨n, rfl⟩ := hn |
| 71 | + rw [← sum_comp (Equiv.mulRight (swap i 0))] |
| 72 | + simp_rw [coe_mulRight, Perm.coe_mul, Function.comp_apply, swap_apply_left, univ_perm_fin_succ, |
| 73 | + sum_map, coe_toEmbedding, Fintype.sum_prod_type, Perm.decomposeFin_symm_apply_zero, sum_const, |
| 74 | + smul_eq_mul, ← mul_sum, Finset.card_univ, Fintype.card_perm, Fintype.card_fin] |
| 75 | + congr |
| 76 | + have es := sum_range_add id 1 (n + 1) |
| 77 | + simp_rw [id_eq, sum_range_one, zero_add, add_comm 1] at es |
| 78 | + rw [Fin.sum_univ_eq_sum_range (· + 1), ← es, sum_range_id, add_tsub_cancel_right, mul_comm] |
| 79 | + |
| 80 | +/-- For odd `n`, the sum of `S` over all permutations is divisible by `n!`. -/ |
| 81 | +lemma sum_modEq_zero_of_odd (hn : Odd n) : ∑ a, S c a ≡ 0 [ZMOD n !] := by |
| 82 | + unfold S; rw [sum_comm] |
| 83 | + conv_lhs => enter [2, i, 2, a]; rw [← Nat.cast_one, ← Nat.cast_add] |
| 84 | + simp_rw [← mul_sum, ← Nat.cast_sum] |
| 85 | + have eqv : ∀ i, c i * ↑(∑ a : Perm (Fin n), ((a i).1 + 1)) = |
| 86 | + c i * ((n - 1)! * (n * (n + 1) / 2) : ℕ) := fun i ↦ by rw [sum_perm_add_one hn.pos] |
| 87 | + rw [sum_congr rfl fun i _ ↦ eqv i, ← sum_mul, |
| 88 | + Nat.mul_div_assoc _ (hn.add_odd odd_one).two_dvd, ← mul_assoc, mul_comm _ n, |
| 89 | + Nat.mul_factorial_pred hn.pos.ne', Nat.cast_mul, ← mul_assoc, ← mul_rotate] |
| 90 | + exact (Int.dvd_mul_left ..).modEq_zero_int |
| 91 | + |
| 92 | +theorem result (hn : Odd n ∧ 1 < n) : ∃ a b, a ≠ b ∧ (n ! : ℤ) ∣ S c a - S c b := by |
| 93 | + by_contra h |
| 94 | + have key := (sum_range_modEq_sum_of_contra h).trans (sum_modEq_zero_of_odd hn.1) |
| 95 | + rw [Int.modEq_zero_iff_dvd, dvd_def] at key; obtain ⟨c, hc⟩ := key |
| 96 | + have feven : 2 ∣ (n ! : ℤ) := mod_cast Nat.dvd_factorial zero_lt_two hn.2 |
| 97 | + nth_rw 3 [← Int.ediv_mul_cancel feven] at hc |
| 98 | + rw [mul_comm, Int.mul_ediv_assoc _ feven, mul_rotate] at hc |
| 99 | + have halfpos : 0 < (n ! : ℤ) / 2 := |
| 100 | + Int.ediv_pos_of_pos_of_dvd (by positivity) zero_le_two feven |
| 101 | + rw [mul_left_inj' halfpos.ne', sub_eq_iff_eq_add] at hc |
| 102 | + rw [← even_iff_two_dvd, ← Int.not_odd_iff_even] at feven |
| 103 | + exact feven ⟨_, hc⟩ |
| 104 | + |
| 105 | +end Imo2001Q4 |
0 commit comments