
# PROBLEMS AND SOLUTIONS OF THE $12^{\mathrm{TH}}$ EUROPEAN MATHEMATICAL CUP
$9^{\text {th }}$ December 2023 - $17^{\text {th }}$ December 2023
Junior Category
## Problems and Solutions
Problem 1. Suppose $a, b, c$ are positive integers such that
$$
\operatorname{gcd}(a, b)+\operatorname{gcd}(a, c)+\operatorname{gcd}(b, c)=b+c+2023
$$
Prove that $\operatorname{gcd}(b, c)=2023$.
Remark: For positive integers $x$ and $y, \operatorname{gcd}(x, y)$ denotes their greatest common divisor.
(Ivan Novak)
Solution. We want to prove $\operatorname{gcd}(a, b)=b$ and $\operatorname{gcd}(a, c)=c$, since then the equality from the problem statement implies $\operatorname{gcd}(b, c)=2023$.
1 point.
Note that $\operatorname{gcd}(a, b)$ is a divisor of $b$ and $\operatorname{gcd}(b, c)$ is a divisor of $c$, so we must have $\operatorname{gcd}(a, b)=\frac{b}{u}$ and $\operatorname{gcd}(a, c)=\frac{b}{v}$ for some positive integers $u, v$ and we have
$$
\frac{b}{u}+\frac{c}{v}+\operatorname{gcd}(b, c)=b+c+2023
$$
We want to prove $u=v=1$ so we need to eliminate other options. We do this by considering some cases.
1 point.
Case I. Both $u$ and $v$ are greater than 1 .
In this case, we have $\operatorname{gcd}(a, b) \leqslant \frac{b}{2}$ and $\operatorname{gcd}(a, c) \leqslant \frac{c}{2}$, so we must have $\operatorname{gcd}(b, c)>\frac{b+c}{2}$. However, $\operatorname{gcd}(b, c)$ is a divisor of $b$ and $c$ so it is not greater than any of them and thus can't exceed their average, so we get a contradiction.
4 points.
Case II. $u=1$ and $v>1$.
In this case, we have
$$
b+\frac{c}{v}+\operatorname{gcd}(b, c)=b+c+2023
$$
which can be rewritten as
$$
\operatorname{gcd}(b, c)=c+2023-\frac{c}{v}
$$
Since $c-\frac{c}{v} \geqslant \frac{c}{2}$, we have $\operatorname{gcd}(b, c) \geqslant \frac{c}{2}+2023$, so it is a divisor of $c$ greater than $\frac{c}{2}$. Thus, it must be equal to $c$, so we conclude that $c$ divides $b$. However, note that $b \mid a$ since $\operatorname{gcd}(a, b)=b$, so we have $c|b| a$ which implies $c \mid a$. But then $\operatorname{gcd}(a, c)=c$, i.e. $v=1$, a contradiction.
Case III. $u>1$ and $v=1$.
This case is analogous to Case II, so we don't need to consider it.
4 points.
Notes on marking:
- The points are all additive.
Problem 2. Let $n \geqslant 5$ be an integer. There are $n$ points in the plane, no three of them collinear. Each day, Tom erases one of the points, until there are three points left. On the $i$-th day, for $1 \leqslant i \leqslant n-3$, before erasing that day's point, Tom writes down the positive integer $v(i)$ such that the convex hull of the points at that moment has $v(i)$ vertices. Finally, he writes down $v(n-2)=3$. Find the greatest possible value that the expression
$$
|v(1)-v(2)|+|v(2)-v(3)|+\ldots+|v(n-3)-v(n-2)|
$$
can obtain among all possible initial configurations of $n$ points and all possible Tom's moves.
Remark. A convex hull of a finite set of points in the plane is the smallest convex polygon containing all the points of the set (inside it or on the boundary).
(Ivan Novak, Namik Agić)
Solution. The answer is $2 n-8$. The construction which achieves the bound is the following:
Take a semicircle $\Omega$ and mark $n-1$ points on it as $B_{1}, \ldots B_{n-1}$, in that order. Mark $A$ as the intersection of tangents to $\Omega$ at $B_{1}, B_{n-1}$ and consider $A$ and $B_{i}$ as $n$ starting points. In the first move, erase $A$, and after the first move erase $B_{i}$ in arbitrary order. It is easy to check that the first summand is $n-4$ and the remaining $n-4$ summands are 1 , giving the desired bound.
3 points.
The proof of the bound is as follows:
The key idea is to look at the contributions of the individual vertices to the sum. We will prove that each vertex $X$ has a contribution at most 2 to the sum. This is more or less immediate, the first possible contribution is when it becomes a vertex on a convex hull, and a second possible contribution is when it is erased from the hull (The sums after and before these 2 events are not affected by $X$, as well as between). Moreover, the points on an initial hull lose 1 possible contribution, and points of the final hull lose 1 possible contribution (consequence of the possibilities for contribution of a vertex).
3 points.
Let $z=v(1)$. From this we get an upper bound in contributions $2 n-z-3$ (Trivially, $z$ is at least 3 ), Now we split into 2 cases to further sharpen this:
1 point.
- If there exists an index $i$ such that $v(i)0$.
Consider the sequence
$$
\left(a_{1}, a_{2}, \ldots, a_{i-1}, a_{i}-1, a_{i+1}+2, a_{i+2}, \ldots, a_{k-1}, a_{k}-1, a_{k+1}, \ldots\right)
$$
i.e. the sequence in which the $i$-th and $k$-th term are reduced by 1 and the $i+1$-th term is increased by 2 .
We claim that this sequence is also sweet and that it achieves the value not greater than $L$.
The sum of its elements is unchanged so the first condition is satisfied.
For the second condition, note that
$$
\frac{a_{i}-1}{2^{i}}+\frac{a_{i+1}+2}{2^{i+1}}+\frac{a_{k}-1}{2^{k}}=\frac{a_{i}}{2^{i}}+\frac{a_{i+1}}{2^{i+1}}+\frac{a_{k}}{2^{k}}-\frac{1}{2^{k}}
$$
so the sum in the second condition decreases, so it remains smaller than 1 .
Finally, we claim that the value of the sum we're minimising didn't increase. Indeed, we have
$$
i\left(a_{i}-1\right)+(i+1)\left(a_{i+1}+2\right)+k\left(a_{k}-1\right)=i a_{i}+(i+1) a_{i+1}+k a_{k}-(k-i-2)
$$
and since $k \geqslant i+2$, this means the sum didn't increase.
Repeating this transformation finitely many times, we obtain a sequence which obtains the minimum and which doesn't have two nonconsecutive indices $i0$. Thus, it suffices to check sequences of the form
$$
(0,0, \ldots, 0, a, b, 0,0, \ldots)
$$
with $i-1$ leading zeroes for some positive integer $i$, and with $a>0, b \geqslant 0$.
6 points.
In this case, we have the conditions
$$
\begin{array}{r}
a+b=2023 \\
2 a+b \leqslant 2^{i+1}
\end{array}
$$
and we're minimising the expression
$$
f(a, b, i)=i a+(i+1) b=2023 i+b
$$
Since $0 \leqslant b<2023$, the optimal value of $i$ is the least one for which the two conditions can be satisfied. We must have $2^{i+1}=2 a+b>2023$, which holds if and only if $i+1 \geqslant 11$, i.e. we must check $i=10$.
3 points.
When $i=10$, we have $a+b=2023,2 a+b \leqslant 2048$, which gives $b \geqslant 1998$, or
$$
10 a+11 b \geqslant 20230+1998=22228
$$
This value can be obtained for $a=25$ and $b=1998$, so we conclude that $L=22228$.
1 point.
## Notes on marking:
- In the first part worth 6 points, 2 points will be awarded if the solution states that we can WLOG have equality in (2).
- Failed attempts of smoothing the sequence will be worth points depending on how close is it to the correct one (1 or 2 points). If it also contains first remark, the total sum is $1+\mathrm{pts}$ on smoothing (not completely additive with smoothing)

## PROBLEMS AND SOLUTIONS OF THE $12^{\mathrm{TH}}$ EUROPEAN MATHEMATICAL CUP $9^{\text {th }}$ December 2023 - $17^{\text {th }}$ December 2023
Senior Category
## Problems and Solutions
Problem 1. Determine all sets of real numbers $S$ such that:
- 1 is the smallest element of $S$,
- for all $x, y \in S$ such that $x>y, \sqrt{x^{2}-y^{2}} \in S$.
(Adian Anibal Santos Sepčić)
Solution. All such sets are the set $\sqrt{\mathbb{N}}=\{\sqrt{n} \mid n \in \mathbb{N}\}$ and the sets $\sqrt{[n]}=\{\sqrt{k} \mid k \leqslant n, k \in \mathbb{N}\}$ for any $n \in \mathbb{N}$. It's easy to check that all such sets satisfy the problem's condition.
1 point.
We will now show that any $S$ that satisfies the two conditions of the problem is of this form. It suffices to show that $S$ can only contain square roots of positive integers and that $\sqrt{n} \in S$ implies that $\sqrt{m} \in S$ for any $m \leqslant n$.
First, note that we have $1 \in S$ so for any $x \in S$ with $x>1$ we have $\sqrt{x^{2}-1} \in S$. Repeated application of this gives that $\sqrt{x^{2}-n} \in S$ for any $n \in \mathbb{N}$ such that $n0$ such that $b\left(f^{t}(s)\right)=b(s)$. By minimality of $t$, it follows that $f^{t}(s)_{b(s)}=1-s_{b(s)}$ but as we have $s_{b(s)+1}=1-s_{b(s)}=s_{b(s)-1}$ we obtain that $b\left(f\left(f^{t}(s)\right)\right)=b(s)+2$ which contradicts the maximality of $b(s)$ in $A$, so no such component $A$ can exist.
4 points.
Now, let us count the possible cycles of length 2. Each cycle of length 2 occurs when we have $f(f(s))=s$ and $b(s)=$ $b(f(s))$, which gives $2 \leqslant b(s) \leqslant n-1$.
We count by fixing either the left or right of the position $b(s)=k$ in a string $s$ as one of $k-1$ "break" points between $0 / 1$ blocks in the string $s$ and then counting that the other $k-2$ block "breakpoints" can be assigned in $\binom{n-3}{k-2}$ ways to the remaining $n-3$ spots between two symbols of $s$, with each assignment of blocks giving two distinct outcomes due to the choice of $0 / 1$ in the starting block. This gives a total of
$$
\sum_{k=2}^{n-1} 2\binom{n-3}{k-2}=2^{n-2}
$$
different cycles of length 2 and we are done.
Problem 4. Let $f: \mathbb{N} \rightarrow \mathbb{N}$ be a function such that for all positive integers $x$ and $y$, the number $f(x)+y$ is a perfect square if and only if $x+f(y)$ is a perfect square. Prove that $f$ is injective.
Remark. A function $f: \mathbb{N} \rightarrow \mathbb{N}$ is injective if for all pairs $(x, y)$ of distinct positive integers, $f(x) \neq f(y)$ holds.
(Ivan Novak)
Solution. Suppose for the sake of contradiction that there exist positive integers $a, b$ and $c$ such that $f(a)=f(b)=c$ and $a>b$. Consider any $x>\sqrt{c}$.
Then, since $x^{2}-c+c=x^{2}-c+f(a)=x^{2}-c+f(b)$ is a square, both $f\left(x^{2}-c\right)+a$ and $f\left(x^{2}-c\right)+b$ are squares. Since $a-b>0$, we have the following bound:
$$
a-b=\left(f\left(x^{2}-c\right)+a\right)-\left(f\left(x^{2}-c\right)+b\right)>\sqrt{f\left(x^{2}-c\right)+a}+\sqrt{f\left(x^{2}-c\right)+b}
$$
This implies that the function $x \mapsto f\left(x^{2}-c\right)$ obtains only finitely many values since otherwise the bound wouldn't hold. By the pigeonhole principle, the expression $f\left(x^{2}-c\right)$ obtains some fixed value $m$ for infinitely many positive integers $x$.
1 point.
Consider a positive integer $y>\sqrt{m}$. Then $y^{2}-m+f\left(x^{2}-c\right)=y^{2}$ for infinitely many values of $x$. This implies that $f\left(y^{2}-m\right)+x^{2}-c$ is a square for infinitely many values of $x$. This implies $f\left(y^{2}-m\right)-c=0$, since it can be written as a difference of squares in infinitely many ways. Thus, $f\left(y^{2}-m\right)=c$ for every $y>\sqrt{m}$.
1 point.
Now, $f\left(y^{2}-m\right)=c$ for infinitely many $y$, so with the same argumentation as above we get $f\left(x^{2}-c\right)=m$ for every $x>\sqrt{c}$.
Lemma. There exists a positive integer $M$ such that for every positive integer $z$ we have $f(z) \leqslant M$ or $f(z) \equiv m+2$ $(\bmod 4)$
Proof. If $z=x^{2}-c$ for some positive integer $x$ then we have $f(z)=m$.
Now assume $z \neq x^{2}-c$ for all positive integers $x$.
Let $y \in \mathbb{N}, y>\sqrt{m}$. If $f(z)+y^{2}-m$ is a square, then $z+f\left(y^{2}-m\right)$ is a square, but $f\left(y^{2}-m\right)=c$, so this is contradiction with the choice of $z$.
So $f(z)+y^{2}-m \neq x^{2}$ for all positive integers $x$.
From this, we have $f(z) \neq x^{2}-y^{2}+m$ for all positive integers $x$ i $y$ such that $y>\sqrt{m}$.
Let $y_{1}$ be the smallest positive integer such that $y_{1}>\sqrt{m}$.
For every $y \geqslant y_{1}$ we have $f(z) \neq(y+1)^{2}-y^{2}+m=2 y+1+m$, so $f(z)$ is either smaller than $2 y_{1}+1+m$ or $f(z)-m \not \equiv 1$ $(\bmod 2)$.
For every $y \geqslant y_{1}$ we have $f(z) \neq(y+2)^{2}-y^{2}+m=4 y+4+m$, so $f(z)$ is either smaller than $4 y_{1}+4+m$ or $f(z)-m \not \equiv 0$ $(\bmod 4)$.
Now $M=4 y_{1}+4+m$ satisfies the claim of the lemma.
5 points.
Take $M$ which satisfies the lemma. Now take $w$ such that $w+1, w+2, \ldots, w+M$ are not squares, and $w+m \equiv 0$ (mod 4). For some $d>\sqrt{f(w)}$
we have $d^{2}-f(w)+f(w)$ is a square so $f\left(d^{2}-f(w)\right)+w$ must be a square, but using the lemma on $z=d^{2}-f(w)$ we get that $f\left(d^{2}-f(w)\right)+w$ is either among $w+1, w+2, \ldots, w+M$ or congruent $2+m+w \equiv 2$ modulo 4 , so it cannot be a square.
Contradiction with the starting assumption, so $f$ must be injective.