Skip to content

Commit 20e1543

Browse files
committed
feat: IMO 1985 Q2
1 parent 9bd9792 commit 20e1543

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

Archive.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import Archive.Imo.Imo1977Q6
2222
import Archive.Imo.Imo1981Q3
2323
import Archive.Imo.Imo1982Q1
2424
import Archive.Imo.Imo1982Q3
25+
import Archive.Imo.Imo1985Q2
2526
import Archive.Imo.Imo1986Q5
2627
import Archive.Imo.Imo1987Q1
2728
import Archive.Imo.Imo1988Q6

Archive/Imo/Imo1985Q2.lean

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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.Order.Ring.Canonical
7+
import Mathlib.Algebra.Order.Ring.Star
8+
import Mathlib.Data.Nat.ModEq
9+
10+
/-!
11+
# IMO 1985 Q2
12+
13+
Each of the numbers in the set $N=\{1, 2, 3, \dots, n-1\}$, where $n ≥ 3$, is colored with one of
14+
two colors, say red or black, so that:
15+
16+
1. $i$ and $n-i$ always receive the same color, and
17+
2. for some $j ∈ N$ relatively prime to $n$, $i$ and $|j-i|$ receive the same color
18+
for all $i ∈ N, i ≠ j$.
19+
20+
Prove that all numbers in $N$ must receive the same color.
21+
22+
# Solution
23+
24+
Let $a \sim b$ denote that $a$ and $b$ have the same color.
25+
Because $j$ is coprime to $n$, every number in $N$ is of the form $kj\bmod n$ for a unique
26+
$1 ≤ k < n$, so it suffices to show that $kj\bmod n \sim (k-1)j\bmod n$ for $1 < k < n$.
27+
In this range of $k$, $kj\bmod n ≠ j$, so
28+
29+
* if $kj\bmod n > j$, $kj\bmod n \sim kj\bmod n - j = (k-1)j\bmod n$ using rule 2;
30+
* if $kj\bmod n < j$, $kj\bmod n \sim j - kj\bmod n \sim n - j + kj\bmod n = (k-1)j\bmod n$
31+
using rule 2 then rule 1.
32+
-/
33+
34+
namespace Imo1985Q2
35+
36+
open Nat
37+
38+
/-- The conditions on the problem's coloring `C`.
39+
Although its domain is all of `ℕ`, we only care about its values in `Set.Ico 1 n`. -/
40+
def Condition (n j : ℕ) (C : ℕ → Bool) : Prop :=
41+
(∀ i ∈ Set.Ico 1 n, C i = C (n - i)) ∧ (∀ i ∈ Set.Ico 1 n, i ≠ j → C i = C (j - i : ℤ).natAbs)
42+
43+
lemma Int.natAbs_sub_nat_of_lt {a b : ℕ} (h : b ≤ a) : (a - b : ℤ).natAbs = a - b := by
44+
omega
45+
46+
lemma Int.natAbs_sub_nat_of_gt {a b : ℕ} (h : a ≤ b) : (a - b : ℤ).natAbs = b - a := by
47+
omega
48+
49+
lemma Nat.mod_sub_comm {a b n : ℕ} (h : b ≤ a % n) : a % n - b = (a - b) % n := by
50+
rcases n.eq_zero_or_pos with rfl | hn; · simp only [mod_zero]
51+
nth_rw 2 [← div_add_mod a n]; rw [Nat.add_sub_assoc h, mul_add_mod]
52+
exact (mod_eq_of_lt <| (sub_le ..).trans_lt (mod_lt a hn)).symm
53+
54+
/-- For `1 ≤ k < n`, `k * j % n` has the same color as `j`. -/
55+
lemma C_mul_mod {n j : ℕ} (hn : 3 ≤ n) (hj : j ∈ Set.Ico 1 n) (cpj : Coprime n j)
56+
{C : ℕ → Bool} (hC : Condition n j C) {k : ℕ} (hk : k ∈ Set.Ico 1 n) :
57+
C (k * j % n) = C j := by
58+
rcases hk.1.eq_or_lt with rfl | (hk₁ : 1 + 1 ≤ k)
59+
· rw [one_mul, mod_eq_of_lt hj.2]
60+
· have nej : k * j % n ≠ j := by
61+
by_contra! h; nth_rw 2 [← mod_eq_of_lt hj.2, ← one_mul j] at h
62+
replace h : k % n = 1 % n := ModEq.cancel_right_of_coprime cpj h
63+
rw [mod_eq_of_lt hk.2, mod_eq_of_lt (by omega)] at h
64+
omega
65+
have b₁ : k * j % n ∈ Set.Ico 1 n := by
66+
refine ⟨?_, mod_lt _ (by omega)⟩
67+
by_contra! h; rw [lt_one_iff, ← dvd_iff_mod_eq_zero] at h
68+
have ek := eq_zero_of_dvd_of_lt (cpj.dvd_of_dvd_mul_right h) hk.2
69+
omega
70+
have hk₂ : k - 1 ∈ Set.Ico 1 n := ⟨le_sub_of_add_le hk₁, (sub_le ..).trans_lt hk.2
71+
rw [← C_mul_mod hn hj cpj hC hk₂, hC.2 _ b₁ nej]
72+
rcases nej.lt_or_lt with h | h
73+
· rw [Int.natAbs_sub_nat_of_lt h.le]
74+
have b₂ : j - k * j % n ∈ Set.Ico 1 n := by
75+
refine ⟨(?_ : 0 < _), (sub_le ..).trans_lt hj.2
76+
rwa [Nat.sub_pos_iff_lt]
77+
have q : n - (j - k * j % n) = k * j % n + (n - j) % n := by
78+
rw [tsub_tsub_eq_add_tsub_of_le h.le, add_comm, Nat.add_sub_assoc hj.2.le,
79+
mod_eq_of_lt (show n - j < n by omega)]
80+
rw [hC.1 _ b₂, q, ← add_mod_of_add_mod_lt (by omega), ← Nat.add_sub_assoc hj.2.le, add_comm,
81+
Nat.add_sub_assoc (Nat.le_mul_of_pos_left _ hk.1), ← tsub_one_mul, add_mod_left]
82+
· rw [Int.natAbs_sub_nat_of_gt h.le, Nat.mod_sub_comm h.le, tsub_one_mul]
83+
84+
theorem result {n j : ℕ} (hn : 3 ≤ n) (hj : j ∈ Set.Ico 1 n) (cpj : Coprime n j)
85+
{C : ℕ → Bool} (hC : Condition n j C) {i : ℕ} (hi : i ∈ Set.Ico 1 n) :
86+
C i = C j := by
87+
obtain ⟨v, hv⟩ := exists_mul_emod_eq_one_of_coprime cpj.symm (by omega)
88+
have hvi : i = (v * i % n) * j % n := by
89+
rw [mod_mul_mod, ← mul_rotate, ← mod_mul_mod, hv, one_mul, mod_eq_of_lt hi.2]
90+
have vib : v * i % n ∈ Set.Ico 1 n := by
91+
refine ⟨(?_ : 0 < _), mod_lt _ (by omega)⟩
92+
by_contra! h; rw [le_zero, ← dvd_iff_mod_eq_zero] at h
93+
rw [mul_comm, ← mod_eq_of_lt (show 1 < n by omega)] at hv
94+
have i0 := eq_zero_of_dvd_of_lt
95+
((coprime_of_mul_modEq_one _ hv).symm.dvd_of_dvd_mul_left h) hi.2
96+
subst i; simp at hi
97+
rw [hvi, C_mul_mod hn hj cpj hC vib]
98+
99+
end Imo1985Q2

0 commit comments

Comments
 (0)