|
| 1 | +/- |
| 2 | +Copyright (c) 2021 Mantas Bakšys. All rights reserved. |
| 3 | +Released under Apache 2.0 license as described in the file LICENSE. |
| 4 | +Authors: Mantas Bakšys |
| 5 | +-/ |
| 6 | + |
| 7 | +import data.real.sqrt |
| 8 | +import tactic.interval_cases |
| 9 | +import tactic.linarith |
| 10 | +import tactic.norm_cast |
| 11 | +import tactic.norm_num |
| 12 | +import tactic.ring_exp |
| 13 | + |
| 14 | +/-! |
| 15 | +# IMO 2021 Q1 |
| 16 | +
|
| 17 | +Let `n≥100` be an integer. Ivan writes the numbers `n, n+1,..., 2n` each on different cards. |
| 18 | +He then shuffles these `n+1` cards, and divides them into two piles. Prove that at least one |
| 19 | +of the piles contains two cards such that the sum of their numbers is a perfect square. |
| 20 | +
|
| 21 | +# Solution |
| 22 | +
|
| 23 | +We show there exists a triplet `a, b, c ∈ [n , 2n]` with `a < b < c` and each of the sums `(a + b)`, |
| 24 | +`(b + c)`, `(a + c)` being a perfect square. Specifically, we consider the linear system of |
| 25 | +equations |
| 26 | +
|
| 27 | + a + b = (2 * l - 1) ^ 2 |
| 28 | + a + c = (2 * l) ^ 2 |
| 29 | + b + c = (2 * l + 1) ^ 2 |
| 30 | +
|
| 31 | +which can be solved to give |
| 32 | +
|
| 33 | + a = 2 * l * l - 4 * l |
| 34 | + b = 2 * l * l + 1 |
| 35 | + c = 2 * l * l + 4 * l |
| 36 | +
|
| 37 | +Therefore, it is enough to show that there exists a natural number l such that |
| 38 | +`n ≤ 2 * l * l - 4 * l` and `2 * l * l + 4 * l ≤ 2 * n` for `n ≥ 100`. |
| 39 | +
|
| 40 | +Then, by the Pigeonhole principle, at least two numbers in the triplet must lie in the same pile, |
| 41 | +which finishes the proof. |
| 42 | +-/ |
| 43 | + |
| 44 | +open real |
| 45 | + |
| 46 | +lemma lower_bound (n l : ℕ) (hl : 2 + sqrt (4 + 2 * n) ≤ 2 * l) : |
| 47 | + n + 4 * l ≤ 2 * l * l := |
| 48 | +begin |
| 49 | + suffices : 2 * ((n : ℝ) + 4 * l) - 8 * l + 4 ≤ 2 * (2 * l * l) - 8 * l + 4, |
| 50 | + { simp only [mul_le_mul_left, sub_le_sub_iff_right, add_le_add_iff_right, zero_lt_two] at this, |
| 51 | + exact_mod_cast this, }, |
| 52 | + rw [← le_sub_iff_add_le', sqrt_le_iff, pow_two] at hl, |
| 53 | + convert hl.2 using 1; ring, |
| 54 | +end |
| 55 | + |
| 56 | +lemma upper_bound (n l : ℕ) (hl : (l : ℝ) ≤ sqrt (1 + n) - 1) : |
| 57 | + 2 * l * l + 4 * l ≤ 2 * n := |
| 58 | +begin |
| 59 | + have h1 : ∀ n : ℕ, 0 ≤ 1 + (n : ℝ), by { intro n, exact_mod_cast nat.zero_le (1 + n) }, |
| 60 | + rw [le_sub_iff_add_le', le_sqrt (h1 l) (h1 n), pow_two] at hl, |
| 61 | + rw [← add_le_add_iff_right 2, ← @nat.cast_le ℝ], |
| 62 | + simp only [nat.cast_bit0, nat.cast_add, nat.cast_one, nat.cast_mul], |
| 63 | + convert (mul_le_mul_left zero_lt_two).mpr hl using 1; ring, |
| 64 | +end |
| 65 | + |
| 66 | + |
| 67 | +lemma radical_inequality {n : ℕ} (h : 107 ≤ n) : sqrt (4 + 2 * n) ≤ 2 * (sqrt (1 + n) - 3) := |
| 68 | +begin |
| 69 | + have h1n : 0 ≤ 1 + (n : ℝ), by { norm_cast, exact nat.zero_le _ }, |
| 70 | + rw sqrt_le_iff, |
| 71 | + split, |
| 72 | + { simp only [sub_nonneg, zero_le_mul_left, zero_lt_two, le_sqrt zero_lt_three.le h1n], |
| 73 | + norm_cast, linarith only [h] }, |
| 74 | + ring_exp, |
| 75 | + rw [pow_two, ← sqrt_mul h1n, sqrt_mul_self h1n], |
| 76 | + suffices : 24 * sqrt (1 + n) ≤ 2 * n + 36, by linarith, |
| 77 | + rw mul_self_le_mul_self_iff, |
| 78 | + swap, { norm_num, apply sqrt_nonneg }, |
| 79 | + swap, { norm_cast, linarith }, |
| 80 | + ring_exp, |
| 81 | + rw [pow_two, ← sqrt_mul h1n, sqrt_mul_self h1n], |
| 82 | + -- Not splitting into cases lead to a deterministic timeout on my machine |
| 83 | + obtain ⟨rfl, h'⟩ : 107 = n ∨ 107 < n := eq_or_lt_of_le h, |
| 84 | + { norm_num }, |
| 85 | + { norm_cast, |
| 86 | + nlinarith }, |
| 87 | +end |
| 88 | + |
| 89 | +-- We will later make use of the fact that there exists (l : ℕ) such that |
| 90 | +-- n ≤ 2 * l * l - 4 * l and 2 * l * l + 4 * l ≤ 2 * n for n ≥ 107. |
| 91 | +lemma exists_numbers_in_interval (n : ℕ) (hn : 107 ≤ n) : |
| 92 | + ∃ (l : ℕ), (n + 4 * l ≤ 2 * l * l ∧ 2 * l * l + 4 * l ≤ 2 * n) := |
| 93 | +begin |
| 94 | + suffices : ∃ (l : ℕ), 2 + sqrt (4 + 2 * n) ≤ 2 * (l : ℝ) ∧ (l : ℝ) ≤ sqrt (1 + n) - 1, |
| 95 | + { cases this with l t, |
| 96 | + exact ⟨l, lower_bound n l t.1, upper_bound n l t.2⟩ }, |
| 97 | + let x := sqrt (1 + n) - 1, |
| 98 | + refine ⟨⌊x⌋₊, _, _⟩, |
| 99 | + { transitivity 2 * (x - 1), |
| 100 | + { dsimp only [x], linarith only [radical_inequality hn] }, |
| 101 | + { simp only [mul_le_mul_left, zero_lt_two], linarith only [(nat.lt_floor_add_one x).le], } }, |
| 102 | + { apply nat.floor_le, rw [sub_nonneg, le_sqrt], |
| 103 | + all_goals { norm_cast, simp only [one_pow, le_add_iff_nonneg_right, zero_le'], } }, |
| 104 | +end |
| 105 | + |
| 106 | +lemma exists_triplet_summing_to_squares (n : ℕ) (hn : 100 ≤ n) : |
| 107 | + (∃ (a b c : ℕ), n ≤ a ∧ a < b ∧ b < c ∧ c ≤ 2 * n ∧ (∃ (k : ℕ), a + b = k * k) ∧ |
| 108 | + (∃ (l : ℕ), c + a = l * l) ∧ (∃ (m : ℕ), b + c = m * m)) := |
| 109 | +begin |
| 110 | + -- If n ≥ 107, we do not explicitly construct the triplet but use an existence |
| 111 | + -- argument from lemma above. |
| 112 | + obtain p|p : 107 ≤ n ∨ n < 107 := le_or_lt 107 n, |
| 113 | + { obtain ⟨l, hl1, hl2⟩ := exists_numbers_in_interval n p, |
| 114 | + have p : 1 < l, { contrapose! hl1, interval_cases l; linarith }, |
| 115 | + have h₁ : 4 * l ≤ 2 * l * l, { linarith }, |
| 116 | + have h₂ : 1 ≤ 2 * l, { linarith }, |
| 117 | + refine ⟨2 * l * l - 4 * l, 2 * l * l + 1, 2 * l * l + 4 * l, |
| 118 | + _, _, _, ⟨_, ⟨2 * l - 1, _⟩, ⟨2 * l, _⟩, 2 * l + 1, _⟩⟩, |
| 119 | + all_goals { zify [h₁, h₂], linarith } }, |
| 120 | + -- Otherwise, if 100 ≤ n < 107, then it suffices to consider explicit |
| 121 | + -- construction of a triplet {a, b, c}, which is constructed by setting l=9 |
| 122 | + -- in the argument at the start of the file. |
| 123 | + { refine ⟨126, 163, 198, p.le.trans _, _, _, _, ⟨17, _⟩, ⟨18, _⟩, 19, _⟩, |
| 124 | + swap 4, { linarith }, |
| 125 | + all_goals { norm_num } }, |
| 126 | +end |
| 127 | + |
| 128 | +-- Since it will be more convenient to work with sets later on, we will translate the above claim |
| 129 | +-- to state that there always exists a set B ⊆ [n, 2n] of cardinality at least 3, such that each |
| 130 | +-- pair of pairwise unequal elements of B sums to a perfect square. |
| 131 | +lemma exists_finset_3_le_card_with_pairs_summing_to_squares (n : ℕ) (hn : 100 ≤ n) : |
| 132 | + ∃ B : finset ℕ, |
| 133 | + (2 * 1 + 1 ≤ B.card) ∧ |
| 134 | + (∀ (a b ∈ B), a ≠ b → ∃ k, a + b = k * k) ∧ |
| 135 | + (∀ (c ∈ B), n ≤ c ∧ c ≤ 2 * n) := |
| 136 | +begin |
| 137 | + obtain ⟨a, b, c, hna, hab, hbc, hcn, h₁, h₂, h₃⟩ := exists_triplet_summing_to_squares n hn, |
| 138 | + refine ⟨{a, b, c}, _, _, _⟩, |
| 139 | + { suffices : ({a, b, c} : finset ℕ).card = 3, { rw this, exact le_rfl }, |
| 140 | + suffices : a ∉ {b, c} ∧ b ∉ {c}, |
| 141 | + { rw [finset.card_insert_of_not_mem this.1, finset.card_insert_of_not_mem this.2, |
| 142 | + finset.card_singleton], }, |
| 143 | + { rw [finset.mem_insert, finset.mem_singleton, finset.mem_singleton], |
| 144 | + push_neg, |
| 145 | + exact ⟨⟨hab.ne, (hab.trans hbc).ne⟩, hbc.ne⟩ } }, |
| 146 | + { intros x y hx hy hxy, |
| 147 | + simp only [finset.mem_insert, finset.mem_singleton] at hx hy, |
| 148 | + rcases hx with rfl|rfl|rfl; rcases hy with rfl|rfl|rfl, |
| 149 | + all_goals { contradiction <|> assumption <|> simpa only [add_comm x y], } }, |
| 150 | + { simp only [finset.mem_insert, finset.mem_singleton], |
| 151 | + rintros d (rfl|rfl|rfl); split; linarith only [hna, hab, hbc, hcn], }, |
| 152 | +end |
| 153 | + |
| 154 | +theorem IMO_2021_Q1 : ∀ (n : ℕ), 100 ≤ n → ∀ (A ⊆ finset.Icc n (2 * n)), |
| 155 | + (∃ (a b ∈ A), a ≠ b ∧ ∃ (k : ℕ), a + b = k * k) ∨ |
| 156 | + (∃ (a b ∈ finset.Icc n (2 * n) \ A), a ≠ b ∧ ∃ (k : ℕ), a + b = k * k) := |
| 157 | +begin |
| 158 | + intros n hn A hA, |
| 159 | + -- For each n ∈ ℕ such that 100 ≤ n, there exists a pairwise unequal triplet {a, b, c} ⊆ [n, 2n] |
| 160 | + -- such that all pairwise sums are perfect squares. In practice, it will be easier to use |
| 161 | + -- a finite set B ⊆ [n, 2n] such that all pairwise unequal pairs of B sum to a perfect square |
| 162 | + -- noting that B has cardinality greater or equal to 3, by the explicit construction of the |
| 163 | + -- triplet {a, b, c} before. |
| 164 | + obtain ⟨B, hB, h₁, h₂⟩ := exists_finset_3_le_card_with_pairs_summing_to_squares n hn, |
| 165 | + have hBsub : B ⊆ finset.Icc n (2 * n), |
| 166 | + { intros c hcB, simpa only [finset.mem_Icc] using h₂ c hcB }, |
| 167 | + have hB' : 2 * 1 < ((B ∩ (finset.Icc n (2 * n) \ A)) ∪ (B ∩ A)).card, |
| 168 | + { rw [← finset.inter_distrib_left, finset.sdiff_union_self_eq_union, |
| 169 | + finset.union_eq_left_iff_subset.mpr hA, (finset.inter_eq_left_iff_subset _ _).mpr hBsub], |
| 170 | + exact nat.succ_le_iff.mp hB }, |
| 171 | + -- Since B has cardinality greater or equal to 3, there must exist a subset C ⊆ B such that |
| 172 | + -- for any A ⊆ [n, 2n], either C ⊆ A or C ⊆ [n, 2n] \ A and C has cardinality greater |
| 173 | + -- or equal to 2. |
| 174 | + obtain ⟨C, hC, hCA⟩ := finset.exists_subset_or_subset_of_two_mul_lt_card hB', |
| 175 | + rw finset.one_lt_card at hC, |
| 176 | + rcases hC with ⟨a, ha, b, hb, hab⟩, |
| 177 | + simp only [finset.subset_iff, finset.mem_inter] at hCA, |
| 178 | + -- Now we split into the two cases C ⊆ [n, 2n] \ A and C ⊆ A, which can be dealt with identically. |
| 179 | + cases hCA; [right, left]; |
| 180 | + exact ⟨a, b, (hCA ha).2, (hCA hb).2, hab, h₁ a b (hCA ha).1 (hCA hb).1 hab⟩, |
| 181 | +end |
0 commit comments