Players $A$ and $B$ play a paintful game on the real line. Player $A$ has a pot of paint with four units of black ink. A quantity $p$ of this ink suffices to blacken a (closed) real interval of length p. In every round, player $A$ picks some positive integer $m$ and provides $1 / 2^{m}$ units of ink from the pot. Player $B$ then picks an integer $k$ and blackens the interval from $k / 2^{m}$ to $(k+1) / 2^{m}$ (some parts of this interval may have been blackened before). The goal of player $A$ is to reach a situation where the pot is empty and the interval $[0,1]$ is not completely blackened.  Decide whether there exists a strategy for player $A$ to win in a finite number of moves.  (Austria)  Answer. No. Such a strategy for player $A$ does not exist.

Solution: We will present a strategy for player $B$ that guarantees that the interval $[0,1]$ is completely blackened, once the paint pot has become empty.  At the beginning of round $r$, let $x_{r}$ denote the largest real number for which the interval between 0 and $x_{r}$ has already been blackened; for completeness we define $x_{1}=0$. Let $m$ be the integer picked by player $A$ in this round; we define an integer $y_{r}$ by  $$ \frac{y_{r}}{2^{m}} \leqslant x_{r}<\frac{y_{r}+1}{2^{m}} $$  Note that $I_{0}^{r}=\left[y_{r} / 2^{m},\left(y_{r}+1\right) / 2^{m}\right]$ is the leftmost interval that may be painted in round $r$ and that still contains some uncolored point.  Player $B$ now looks at the next interval $I_{1}^{r}=\left[\left(y_{r}+1\right) / 2^{m},\left(y_{r}+2\right) / 2^{m}\right]$. If $I_{1}^{r}$ still contains an uncolored point, then player $B$ blackens the interval $I_{1}^{r}$; otherwise he blackens the interval $I_{0}^{r}$. We make the convention that, at the beginning of the game, the interval $[1,2]$ is already blackened; thus, if $y_{r}+1=2^{m}$, then $B$ blackens $I_{0}^{r}$.  Our aim is to estimate the amount of ink used after each round. Firstly, we will prove by induction that, if before $r$ th round the segment $[0,1]$ is not completely colored, then, before this move,  (i) the amount of ink used for the segment $\left[0, x_{r}\right]$ is at most $3 x_{r}$; and  (ii) for every $m, B$ has blackened at most one interval of length $1 / 2^{m}$ to the right of $x_{r}$.  Obviously, these conditions are satisfied for $r=0$. Now assume that they were satisfied before the $r$ th move, and consider the situation after this move; let $m$ be the number $A$ has picked at this move.  If $B$ has blackened the interval $I_{1}^{r}$ at this move, then $x_{r+1}=x_{r}$, and $(i)$ holds by the induction hypothesis. Next, had $B$ blackened before the $r$ th move any interval of length $1 / 2^{m}$ to the right of $x_{r}$, this interval would necessarily coincide with $I_{1}^{r}$. By our strategy, this cannot happen. So, condition (ii) also remains valid.  Assume now that $B$ has blackened the interval $I_{0}^{r}$ at the $r$ th move, but the interval $[0,1]$ still contains uncolored parts (which means that $I_{1}^{r}$ is contained in $[0,1]$ ). Then condition (ii) clearly remains true, and we need to check ( $i$ ) only. In our case, the intervals $I_{0}^{r}$ and $I_{1}^{r}$ are completely colored after the $r$ th move, so $x_{r+1}$ either reaches the right endpoint of $I_{1}$ or moves even further to the right. So, $x_{r+1}=x_{r}+\alpha$ for some $\alpha>1 / 2^{m}$.  Next, any interval blackened by $B$ before the $r$ th move which intersects $\left(x_{r}, x_{r+1}\right)$ should be contained in $\left[x_{r}, x_{r+1}\right]$; by (ii), all such intervals have different lengths not exceeding $1 / 2^{m}$, so the total amount of ink used for them is less than $2 / 2^{m}$. Thus, the amount of ink used for the segment $\left[0, x_{r+1}\right]$ does not exceed the sum of $2 / 2^{m}, 3 x_{r}$ (used for $\left[0, x_{r}\right]$ ), and $1 / 2^{m}$ used for the segment $I_{0}^{r}$. In total it gives at most $3\left(x_{r}+1 / 2^{m}\right)<3\left(x_{r}+\alpha\right)=3 x_{r+1}$. Thus condition $(i)$ is also verified in this case. The claim is proved.  Finally, we can perform the desired estimation. Consider any situation in the game, say after the $(r-1)$ st move; assume that the segment $[0,1]$ is not completely black. By $(i i)$, in the segment $\left[x_{r}, 1\right]$ player $B$ has colored several segments of different lengths; all these lengths are negative powers of 2 not exceeding $1-x_{r}$; thus the total amount of ink used for this interval is at most $2\left(1-x_{r}\right)$. Using $(i)$, we obtain that the total amount of ink used is at most $3 x_{r}+2\left(1-x_{r}\right)<3$. Thus the pot is not empty, and therefore $A$ never wins.  Comment 1. Notice that this strategy works even if the pot contains initially only 3 units of ink.  Comment 2. There exist other strategies for $B$ allowing him to prevent emptying the pot before the whole interval is colored. On the other hand, let us mention some idea which does not work.  Player $B$ could try a strategy in which the set of blackened points in each round is an interval of the type $[0, x]$. Such a strategy cannot work (even if there is more ink available). Indeed, under the assumption that $B$ uses such a strategy, let us prove by induction on $s$ the following statement:  For any positive integer $s$, player $A$ has a strategy picking only positive integers $m \leqslant s$ in which, if player $B$ ever paints a point $x \geqslant 1-1 / 2^{s}$ then after some move, exactly the interval $\left[0,1-1 / 2^{s}\right]$ is blackened, and the amount of ink used up to this moment is at least s/2.  For the base case $s=1$, player $A$ just picks $m=1$ in the first round. If for some positive integer $k$ player $A$ has such a strategy, for $s+1$ he can first rescale his strategy to the interval $[0,1 / 2]$ (sending in each round half of the amount of ink he would give by the original strategy). Thus, after some round, the interval $\left[0,1 / 2-1 / 2^{s+1}\right]$ becomes blackened, and the amount of ink used is at least $s / 4$. Now player $A$ picks $m=1 / 2$, and player $B$ spends $1 / 2$ unit of ink to blacken the interval [0,1/2]. After that, player $A$ again rescales his strategy to the interval $[1 / 2,1]$, and player $B$ spends at least $s / 4$ units of ink to blacken the interval $\left[1 / 2,1-1 / 2^{s+1}\right]$, so he spends in total at least $s / 4+1 / 2+s / 4=(s+1) / 2$ units of ink.  Comment 3. In order to avoid finiteness issues, the statement could be replaced by the following one:  Players $A$ and $B$ play a paintful game on the real numbers. Player $A$ has a paint pot with four units of black ink. A quantity $p$ of this ink suffices to blacken a (closed) real interval of length $p$. In the beginning of the game, player $A$ chooses (and announces) a positive integer $N$. In every round, player $A$ picks some positive integer $m \leqslant N$ and provides $1 / 2^{m}$ units of ink from the pot. The player $B$ picks an integer $k$ and blackens the interval from $k / 2^{m}$ to $(k+1) / 2^{m}$ (some parts of this interval may happen to be blackened before). The goal of player $A$ is to reach a situation where the pot is empty and the interval $[0,1]$ is not completely blackened.  Decide whether there exists a strategy for player A to win.  However, the Problem Selection Committee believes that this version may turn out to be harder than the original one.


Let $A B C D E F$ be a convex hexagon with $A B=D E, B C=E F, C D=F A$, and $\angle A-\angle D=\angle C-\angle F=\angle E-\angle B$. Prove that the diagonals $A D, B E$, and $C F$ are concurrent.  (Ukraine)  In all three solutions, we denote $\theta=\angle A-\angle D=\angle C-\angle F=\angle E-\angle B$ and assume without loss of generality that $\theta \geqslant 0$.

Solution: Let $x=A B=D E, y=C D=F A, z=E F=B C$. Consider the points $P, Q$, and $R$ such that the quadrilaterals $C D E P, E F A Q$, and $A B C R$ are parallelograms. We compute  $$ \begin{aligned} \angle P E Q & =\angle F E Q+\angle D E P-\angle E=\left(180^{\circ}-\angle F\right)+\left(180^{\circ}-\angle D\right)-\angle E \\ & =360^{\circ}-\angle D-\angle E-\angle F=\frac{1}{2}(\angle A+\angle B+\angle C-\angle D-\angle E-\angle F)=\theta / 2 \end{aligned} $$  Similarly, $\angle Q A R=\angle R C P=\theta / 2$.  ![](https://cdn.mathpix.com/cropped/2024_04_17_e0914cb4f8055c731538g-46.jpg?height=491&width=827&top_left_y=947&top_left_x=649)  If $\theta=0$, since $\triangle R C P$ is isosceles, $R=P$. Therefore $A B\|R C=P C\| E D$, so $A B D E$ is a parallelogram. Similarly, $B C E F$ and $C D F A$ are parallelograms. It follows that $A D, B E$ and $C F$ meet at their common midpoint.  Now assume $\theta>0$. Since $\triangle P E Q, \triangle Q A R$, and $\triangle R C P$ are isosceles and have the same angle at the apex, we have $\triangle P E Q \sim \triangle Q A R \sim \triangle R C P$ with ratios of similarity $y: z: x$. Thus  $\triangle P Q R$ is similar to the triangle with sidelengths $y, z$, and $x$.  Next, notice that  $$ \frac{R Q}{Q P}=\frac{z}{y}=\frac{R A}{A F} $$  and, using directed angles between rays,  $$ \begin{aligned} \not(R Q, Q P) & =\Varangle(R Q, Q E)+\Varangle(Q E, Q P) \\ & =\Varangle(R Q, Q E)+\Varangle(R A, R Q)=\Varangle(R A, Q E)=\Varangle(R A, A F) . \end{aligned} $$  Thus $\triangle P Q R \sim \triangle F A R$. Since $F A=y$ and $A R=z$, (1) then implies that $F R=x$. Similarly $F P=x$. Therefore $C R F P$ is a rhombus.  We conclude that $C F$ is the perpendicular bisector of $P R$. Similarly, $B E$ is the perpendicular bisector of $P Q$ and $A D$ is the perpendicular bisector of $Q R$. It follows that $A D, B E$, and $C F$ are concurrent at the circumcenter of $P Q R$.


Solution: Let $X=C D \cap E F, Y=E F \cap A B, Z=A B \cap C D, X^{\prime}=F A \cap B C, Y^{\prime}=$ $B C \cap D E$, and $Z^{\prime}=D E \cap F A$. From $\angle A+\angle B+\angle C=360^{\circ}+\theta / 2$ we get $\angle A+\angle B>180^{\circ}$ and $\angle B+\angle C>180^{\circ}$, so $Z$ and $X^{\prime}$ are respectively on the opposite sides of $B C$ and $A B$ from the hexagon. Similar conclusions hold for $X, Y, Y^{\prime}$, and $Z^{\prime}$. Then  $$ \angle Y Z X=\angle B+\angle C-180^{\circ}=\angle E+\angle F-180^{\circ}=\angle Y^{\prime} Z^{\prime} X^{\prime}, $$  and similarly $\angle Z X Y=\angle Z^{\prime} X^{\prime} Y^{\prime}$ and $\angle X Y Z=\angle X^{\prime} Y^{\prime} Z^{\prime}$, so $\triangle X Y Z \sim \triangle X^{\prime} Y^{\prime} Z^{\prime}$. Thus there is a rotation $R$ which sends $\triangle X Y Z$ to a triangle with sides parallel to $\triangle X^{\prime} Y^{\prime} Z^{\prime}$. Since $A B=D E$ we have $R(\overrightarrow{A B})=\overrightarrow{D E}$. Similarly, $R(\overrightarrow{C D})=\overrightarrow{F A}$ and $R(\overrightarrow{E F})=\overrightarrow{B C}$. Therefore  $$ \overrightarrow{0}=\overrightarrow{A B}+\overrightarrow{B C}+\overrightarrow{C D}+\overrightarrow{D E}+\overrightarrow{E F}+\overrightarrow{F A}=(\overrightarrow{A B}+\overrightarrow{C D}+\overrightarrow{E F})+R(\overrightarrow{A B}+\overrightarrow{C D}+\overrightarrow{E F}) $$  If $R$ is a rotation by $180^{\circ}$, then any two opposite sides of our hexagon are equal and parallel, so the three diagonals meet at their common midpoint. Otherwise, we must have  $$ \overrightarrow{A B}+\overrightarrow{C D}+\overrightarrow{E F}=\overrightarrow{0} $$  or else we would have two vectors with different directions whose sum is $\overrightarrow{0}$.  ![](https://cdn.mathpix.com/cropped/2024_04_17_e0914cb4f8055c731538g-47.jpg?height=689&width=1333&top_left_y=1057&top_left_x=388)  This allows us to consider a triangle $L M N$ with $\overrightarrow{L M}=\overrightarrow{E F}, \overrightarrow{M N}=\overrightarrow{A B}$, and $\overrightarrow{N L}=\overrightarrow{C D}$. Let $O$ be the circumcenter of $\triangle L M N$ and consider the points $O_{1}, O_{2}, O_{3}$ such that $\triangle A O_{1} B, \triangle C O_{2} D$, and $\triangle E O_{3} F$ are translations of $\triangle M O N, \triangle N O L$, and $\triangle L O M$, respectively. Since $F O_{3}$ and $A O_{1}$ are translations of $M O$, quadrilateral $A F O_{3} O_{1}$ is a parallelogram and $O_{3} O_{1}=F A=C D=N L$. Similarly, $O_{1} O_{2}=L M$ and $O_{2} O_{3}=M N$. Therefore $\triangle O_{1} O_{2} O_{3} \cong \triangle L M N$. Moreover, by means of the rotation $R$ one may check that these triangles have the same orientation.  Let $T$ be the circumcenter of $\triangle O_{1} O_{2} O_{3}$. We claim that $A D, B E$, and $C F$ meet at $T$. Let us show that $C, T$, and $F$ are collinear. Notice that $C O_{2}=O_{2} T=T O_{3}=O_{3} F$ since they are all equal to the circumradius of $\triangle L M N$. Therefore $\triangle T O_{3} F$ and $\triangle C O_{2} T$ are isosceles. Using directed angles between rays again, we get  $$ \Varangle\left(T F, T O_{3}\right)=\Varangle\left(F O_{3}, F T\right) \quad \text { and } \quad \Varangle\left(T O_{2}, T C\right)=\Varangle\left(C T, C O_{2}\right) \text {. } $$  Also, $T$ and $O$ are the circumcenters of the congruent triangles $\triangle O_{1} O_{2} O_{3}$ and $\triangle L M N$ so we have $\Varangle\left(T O_{3}, T O_{2}\right)=\Varangle(O N, O M)$. Since $C_{2}$ and $F O_{3}$ are translations of $N O$ and $M O$ respectively, this implies  $$ \Varangle\left(T O_{3}, T O_{2}\right)=\Varangle\left(C O_{2}, F O_{3}\right) . $$  Adding the three equations in (2) and (3) gives  $$ \Varangle(T F, T C)=\Varangle(C T, F T)=-\not(T F, T C) $$  which implies that $T$ is on $C F$. Analogous arguments show that it is on $A D$ and $B E$ also. The desired result follows.


Solution: Place the hexagon on the complex plane, with $A$ at the origin and vertices labelled clockwise. Now $A, B, C, D, E, F$ represent the corresponding complex numbers. Also consider the complex numbers $a, b, c, a^{\prime}, b^{\prime}, c^{\prime}$ given by $B-A=a, D-C=b, F-E=c, E-D=a^{\prime}$, $A-F=b^{\prime}$, and $C-B=c^{\prime}$. Let $k=|a| /|b|$. From $a / b^{\prime}=-k e^{i \angle A}$ and $a^{\prime} / b=-k e^{i \angle D}$ we get that $\left(a^{\prime} / a\right)\left(b^{\prime} / b\right)=e^{-i \theta}$ and similarly $\left(b^{\prime} / b\right)\left(c^{\prime} / c\right)=e^{-i \theta}$ and $\left(c^{\prime} / c\right)\left(a^{\prime} / a\right)=e^{-i \theta}$. It follows that $a^{\prime}=a r$, $b^{\prime}=b r$, and $c^{\prime}=c r$ for a complex number $r$ with $|r|=1$, as shown below.  ![](https://cdn.mathpix.com/cropped/2024_04_17_e0914cb4f8055c731538g-48.jpg?height=512&width=1052&top_left_y=823&top_left_x=534)  We have  $$ 0=a+c r+b+a r+c+b r=(a+b+c)(1+r) . $$  If $r=-1$, then the hexagon is centrally symmetric and its diagonals intersect at its center of symmetry. Otherwise  $$ a+b+c=0 \text {. } $$  Therefore  $$ A=0, \quad B=a, \quad C=a+c r, \quad D=c(r-1), \quad E=-b r-c, \quad F=-b r . $$  Now consider a point $W$ on $A D$ given by the complex number $c(r-1) \lambda$, where $\lambda$ is a real number with $0<\lambda<1$. Since $D \neq A$, we have $r \neq 1$, so we can define $s=1 /(r-1)$. From $r \bar{r}=|r|^{2}=1$ we get  $$ 1+s=\frac{r}{r-1}=\frac{r}{r-r \bar{r}}=\frac{1}{1-\bar{r}}=-\bar{s} . $$  Now,  $$ \begin{aligned} W \text { is on } B E & \Longleftrightarrow c(r-1) \lambda-a\|a-(-b r-c)=b(r-1) \Longleftrightarrow c \lambda-a s\| b \\ & \Longleftrightarrow-a \lambda-b \lambda-a s\|b \Longleftrightarrow a(\lambda+s)\| b . \end{aligned} $$  One easily checks that $r \neq \pm 1$ implies that $\lambda+s \neq 0$ since $s$ is not real. On the other hand,  $$ \begin{aligned} W \text { on } C F & \Longleftrightarrow c(r-1) \lambda+b r\|-b r-(a+c r)=a(r-1) \Longleftrightarrow c \lambda+b(1+s)\| a \\ & \Longleftrightarrow-a \lambda-b \lambda-b \bar{s}\|a \Longleftrightarrow b(\lambda+\bar{s})\| a \Longleftrightarrow b \| a(\lambda+s), \end{aligned} $$  where in the last step we use that $(\lambda+s)(\lambda+\bar{s})=|\lambda+s|^{2} \in \mathbb{R}_{>0}$. We conclude that $A D \cap B E=$ $C F \cap B E$, and the desired result follows.


Let $\mathbb{Z}_{>0}$ be the set of positive integers. Find all functions $f: \mathbb{Z}_{>0} \rightarrow \mathbb{Z}_{>0}$ such that  $$ m^{2}+f(n) \mid m f(m)+n $$  for all positive integers $m$ and $n$.  (Malaysia)  Answer. $f(n)=n$.

Solution: Setting $m=n=2$ tells us that $4+f(2) \mid 2 f(2)+2$. Since $2 f(2)+2<2(4+f(2))$, we must have $2 f(2)+2=4+f(2)$, so $f(2)=2$. Plugging in $m=2$ then tells us that $4+f(n) \mid 4+n$, which implies that $f(n) \leqslant n$ for all $n$.  Setting $m=n$ gives $n^{2}+f(n) \mid n f(n)+n$, so $n f(n)+n \geqslant n^{2}+f(n)$ which we rewrite as $(n-1)(f(n)-n) \geqslant 0$. Therefore $f(n) \geqslant n$ for all $n \geqslant 2$. This is trivially true for $n=1$ also.  It follows that $f(n)=n$ for all $n$. This function obviously satisfies the desired property.


Solution: Setting $m=f(n)$ we get $f(n)(f(n)+1) \mid f(n) f(f(n))+n$. This implies that $f(n) \mid n$ for all $n$.  Now let $m$ be any positive integer, and let $p>2 m^{2}$ be a prime number. Note that $p>m f(m)$ also. Plugging in $n=p-m f(m)$ we learn that $m^{2}+f(n)$ divides $p$. Since $m^{2}+f(n)$ cannot equal 1, it must equal $p$. Therefore $p-m^{2}=f(n) \mid n=p-m f(m)$. But $p-m f(m)<p<2\left(p-m^{2}\right)$, so we must have $p-m f(m)=p-m^{2}$, i.e., $f(m)=m$.


Solution: Plugging $m=1$ we obtain $1+f(n) \leqslant f(1)+n$, so $f(n) \leqslant n+c$ for the constant $c=$ $f(1)-1$. Assume that $f(n) \neq n$ for some fixed $n$. When $m$ is large enough (e.g. $m \geqslant \max (n, c+1)$ ) we have  $$ m f(m)+n \leqslant m(m+c)+n \leqslant 2 m^{2}<2\left(m^{2}+f(n)\right), $$  so we must have $m f(m)+n=m^{2}+f(n)$. This implies that  $$ 0 \neq f(n)-n=m(f(m)-m) $$  which is impossible for $m>|f(n)-n|$. It follows that $f$ is the identity function.


Determine whether there exists an infinite sequence of nonzero digits $a_{1}, a_{2}, a_{3}, \ldots$ and a positive integer $N$ such that for every integer $k>N$, the number $\overline{a_{k} a_{k-1} \ldots a_{1}}$ is a perfect square.  (Iran)  Answer. No.

Solution: Assume that $a_{1}, a_{2}, a_{3}, \ldots$ is such a sequence. For each positive integer $k$, let $y_{k}=$ $\overline{a_{k} a_{k-1} \ldots a_{1}}$. By the assumption, for each $k>N$ there exists a positive integer $x_{k}$ such that $y_{k}=x_{k}^{2}$.  I. For every $n$, let $5^{\gamma_{n}}$ be the greatest power of 5 dividing $x_{n}$. Let us show first that $2 \gamma_{n} \geqslant n$ for every positive integer $n>N$.  Assume, to the contrary, that there exists a positive integer $n>N$ such that $2 \gamma_{n}<n$, which yields  $$ y_{n+1}=\overline{a_{n+1} a_{n} \ldots a_{1}}=10^{n} a_{n+1}+\overline{a_{n} a_{n-1} \ldots a_{1}}=10^{n} a_{n+1}+y_{n}=5^{2 \gamma_{n}}\left(2^{n} 5^{n-2 \gamma_{n}} a_{n+1}+\frac{y_{n}}{5^{2 \gamma_{n}}}\right) . $$  Since $5 \nmid y_{n} / 5^{2 \gamma_{n}}$, we obtain $\gamma_{n+1}=\gamma_{n}<n<n+1$. By the same arguments we obtain that $\gamma_{n}=\gamma_{n+1}=\gamma_{n+2}=\ldots$. Denote this common value by $\gamma$.  Now, for each $k \geqslant n$ we have  $$ \left(x_{k+1}-x_{k}\right)\left(x_{k+1}+x_{k}\right)=x_{k+1}^{2}-x_{k}^{2}=y_{k+1}-y_{k}=a_{k+1} \cdot 10^{k} . $$  One of the numbers $x_{k+1}-x_{k}$ and $x_{k+1}+x_{k}$ is not divisible by $5^{\gamma+1}$ since otherwise one would have $5^{\gamma+1} \mid\left(\left(x_{k+1}-x_{k}\right)+\left(x_{k+1}+x_{k}\right)\right)=2 x_{k+1}$. On the other hand, we have $5^{k} \mid\left(x_{k+1}-x_{k}\right)\left(x_{k+1}+x_{k}\right)$, so $5^{k-\gamma}$ divides one of these two factors. Thus we get  $$ 5^{k-\gamma} \leqslant \max \left\{x_{k+1}-x_{k}, x_{k+1}+x_{k}\right\}<2 x_{k+1}=2 \sqrt{y_{k+1}}<2 \cdot 10^{(k+1) / 2} $$  which implies $5^{2 k}<4 \cdot 5^{2 \gamma} \cdot 10^{k+1}$, or $(5 / 2)^{k}<40 \cdot 5^{2 \gamma}$. The last inequality is clearly false for sufficiently large values of $k$. This contradiction shows that $2 \gamma_{n} \geqslant n$ for all $n>N$.  II. Consider now any integer $k>\max \{N / 2,2\}$. Since $2 \gamma_{2 k+1} \geqslant 2 k+1$ and $2 \gamma_{2 k+2} \geqslant 2 k+2$, we have $\gamma_{2 k+1} \geqslant k+1$ and $\gamma_{2 k+2} \geqslant k+1$. So, from $y_{2 k+2}=a_{2 k+2} \cdot 10^{2 k+1}+y_{2 k+1}$ we obtain $5^{2 k+2} \mid y_{2 k+2}-y_{2 k+1}=a_{2 k+2} \cdot 10^{2 k+1}$ and thus $5 \mid a_{2 k+2}$, which implies $a_{2 k+2}=5$. Therefore,  $$ \left(x_{2 k+2}-x_{2 k+1}\right)\left(x_{2 k+2}+x_{2 k+1}\right)=x_{2 k+2}^{2}-x_{2 k+1}^{2}=y_{2 k+2}-y_{2 k+1}=5 \cdot 10^{2 k+1}=2^{2 k+1} \cdot 5^{2 k+2} . $$  Setting $A_{k}=x_{2 k+2} / 5^{k+1}$ and $B_{k}=x_{2 k+1} / 5^{k+1}$, which are integers, we obtain  $$ \left(A_{k}-B_{k}\right)\left(A_{k}+B_{k}\right)=2^{2 k+1} . $$  Both $A_{k}$ and $B_{k}$ are odd, since otherwise $y_{2 k+2}$ or $y_{2 k+1}$ would be a multiple of 10 which is false by $a_{1} \neq 0$; so one of the numbers $A_{k}-B_{k}$ and $A_{k}+B_{k}$ is not divisible by 4 . Therefore (1) yields $A_{k}-B_{k}=2$ and $A_{k}+B_{k}=2^{2 k}$, hence $A_{k}=2^{2 k-1}+1$ and thus  $$ x_{2 k+2}=5^{k+1} A_{k}=10^{k+1} \cdot 2^{k-2}+5^{k+1}>10^{k+1}, $$  since $k \geqslant 2$. This implies that $y_{2 k+2}>10^{2 k+2}$ which contradicts the fact that $y_{2 k+2}$ contains $2 k+2$ digits. The desired result follows.


Solution: Again, we assume that a sequence $a_{1}, a_{2}, a_{3}, \ldots$ satisfies the problem conditions, introduce the numbers $x_{k}$ and $y_{k}$ as in the previous solution, and notice that  $$ y_{k+1}-y_{k}=\left(x_{k+1}-x_{k}\right)\left(x_{k+1}+x_{k}\right)=10^{k} a_{k+1} $$  for all $k>N$. Consider any such $k$. Since $a_{1} \neq 0$, the numbers $x_{k}$ and $x_{k+1}$ are not multiples of 10 , and therefore the numbers $p_{k}=x_{k+1}-x_{k}$ and $q_{k}=x_{k+1}+x_{k}$ cannot be simultaneously multiples of 20 , and hence one of them is not divisible either by 4 or by 5 . In view of (2), this means that the other one is divisible by either $5^{k}$ or by $2^{k-1}$. Notice also that $p_{k}$ and $q_{k}$ have the same parity, so both are even.  On the other hand, we have $x_{k+1}^{2}=x_{k}^{2}+10^{k} a_{k+1} \geqslant x_{k}^{2}+10^{k}>2 x_{k}^{2}$, so $x_{k+1} / x_{k}>\sqrt{2}$, which implies that  $$ 1<\frac{q_{k}}{p_{k}}=1+\frac{2}{x_{k+1} / x_{k}-1}<1+\frac{2}{\sqrt{2}-1}<6 . $$  Thus, if one of the numbers $p_{k}$ and $q_{k}$ is divisible by $5^{k}$, then we have  $$ 10^{k+1}>10^{k} a_{k+1}=p_{k} q_{k} \geqslant \frac{\left(5^{k}\right)^{2}}{6} $$  and hence $(5 / 2)^{k}<60$ which is false for sufficiently large $k$. So, assuming that $k$ is large, we get that $2^{k-1}$ divides one of the numbers $p_{k}$ and $q_{k}$. Hence  $$ \left\{p_{k}, q_{k}\right\}=\left\{2^{k-1} \cdot 5^{r_{k}} b_{k}, 2 \cdot 5^{k-r_{k}} c_{k}\right\} \quad \text { with nonnegative integers } b_{k}, c_{k}, r_{k} \text { such that } b_{k} c_{k}=a_{k+1} \text {. } $$  Moreover, from (3) we get  $$ 6>\frac{2^{k-1} \cdot 5^{r_{k}} b_{k}}{2 \cdot 5^{k-r_{k}} c_{k}} \geqslant \frac{1}{36} \cdot\left(\frac{2}{5}\right)^{k} \cdot 5^{2 r_{k}} \quad \text { and } \quad 6>\frac{2 \cdot 5^{k-r_{k}} c_{k}}{2^{k-1} \cdot 5^{r_{k}} b_{k}} \geqslant \frac{4}{9} \cdot\left(\frac{5}{2}\right)^{k} \cdot 5^{-2 r_{k}} $$  SO  $$ \alpha k+c_{1}<r_{k}<\alpha k+c_{2} \quad \text { for } \alpha=\frac{1}{2} \log _{5}\left(\frac{5}{2}\right)<1 \text { and some constants } c_{2}>c_{1} \text {. } $$  Consequently, for $C=c_{2}-c_{1}+1-\alpha>0$ we have  $$ (k+1)-r_{k+1} \leqslant k-r_{k}+C . $$  Next, we will use the following easy lemma.  Lemma. Let $s$ be a positive integer. Then $5^{s+2^{s}} \equiv 5^{s}\left(\bmod 10^{s}\right)$.  Proof. Euler's theorem gives $5^{2^{s}} \equiv 1\left(\bmod 2^{s}\right)$, so $5^{s+2^{s}}-5^{s}=5^{s}\left(5^{2^{s}}-1\right)$ is divisible by $2^{s}$ and $5^{s}$.  Now, for every large $k$ we have  $$ x_{k+1}=\frac{p_{k}+q_{k}}{2}=5^{r_{k}} \cdot 2^{k-2} b_{k}+5^{k-r_{k}} c_{k} \equiv 5^{k-r_{k}} c_{k} \quad\left(\bmod 10^{r_{k}}\right) $$  since $r_{k} \leqslant k-2$ by $(4)$; hence $y_{k+1} \equiv 5^{2\left(k-r_{k}\right)} c_{k}^{2}\left(\bmod 10^{r_{k}}\right)$. Let us consider some large integer $s$, and choose the minimal $k$ such that $2\left(k-r_{k}\right) \geqslant s+2^{s}$; it exists by (4). Set $d=2\left(k-r_{k}\right)-\left(s+2^{s}\right)$. By (4) we have $2^{s}<2\left(k-r_{k}\right)<\left(\frac{2}{\alpha}-2\right) r_{k}-\frac{2 c_{1}}{\alpha}$; if $s$ is large this implies $r_{k}>s$, so (6) also holds modulo $10^{s}$. Then (6) and the lemma give  $$ y_{k+1} \equiv 5^{2\left(k-r_{k}\right)} c_{k}^{2}=5^{s+2^{s}} \cdot 5^{d} c_{k}^{2} \equiv 5^{s} \cdot 5^{d} c_{k}^{2} \quad\left(\bmod 10^{s}\right) . $$  By (5) and the minimality of $k$ we have $d \leqslant 2 C$, so $5^{d} c_{k}^{2} \leqslant 5^{2 C} \cdot 81=D$. Using $5^{4}<10^{3}$ we obtain  $$ 5^{s} \cdot 5^{d} c_{k}^{2}<10^{3 s / 4} D<10^{s-1} $$  for sufficiently large $s$. This, together with (7), shows that the sth digit from the right in $y_{k+1}$, which is $a_{s}$, is zero. This contradicts the problem condition.


Determine all functions $f: \mathbb{Q} \longrightarrow \mathbb{Z}$ satisfying  $$ f\left(\frac{f(x)+a}{b}\right)=f\left(\frac{x+a}{b}\right) $$  for all $x \in \mathbb{Q}, a \in \mathbb{Z}$, and $b \in \mathbb{Z}_{>0}$. (Here, $\mathbb{Z}_{>0}$ denotes the set of positive integers.)  (Israel)  Answer. There are three kinds of such functions, which are: all constant functions, the floor function, and the ceiling function.

Solution: I. We start by verifying that these functions do indeed satisfy (1). This is clear for all constant functions. Now consider any triple $(x, a, b) \in \mathbb{Q} \times \mathbb{Z} \times \mathbb{Z}_{>0}$ and set  $$ q=\left\lfloor\frac{x+a}{b}\right\rfloor . $$  This means that $q$ is an integer and $b q \leqslant x+a<b(q+1)$. It follows that $b q \leqslant\lfloor x\rfloor+a<b(q+1)$ holds as well, and thus we have  $$ \left\lfloor\frac{\lfloor x\rfloor+a}{b}\right\rfloor=\left\lfloor\frac{x+a}{b}\right\rfloor, $$  meaning that the floor function does indeed satisfy (1). One can check similarly that the ceiling function has the same property.  II. Let us now suppose conversely that the function $f: \mathbb{Q} \longrightarrow \mathbb{Z}$ satisfies (1) for all $(x, a, b) \in$ $\mathbb{Q} \times \mathbb{Z} \times \mathbb{Z}_{>0}$. According to the behaviour of the restriction of $f$ to the integers we distinguish two cases.  Case 1: There is some $m \in \mathbb{Z}$ such that $f(m) \neq m$.  Write $f(m)=C$ and let $\eta \in\{-1,+1\}$ and $b$ denote the sign and absolute value of $f(m)-m$, respectively. Given any integer $r$, we may plug the triple $(m, r b-C, b)$ into (1), thus getting $f(r)=f(r-\eta)$. Starting with $m$ and using induction in both directions, we deduce from this that the equation $f(r)=C$ holds for all integers $r$. Now any rational number $y$ can be written in the form $y=\frac{p}{q}$ with $(p, q) \in \mathbb{Z} \times \mathbb{Z}_{>0}$, and substituting $(C-p, p-C, q)$ into (1) we get $f(y)=f(0)=C$. Thus $f$ is the constant function whose value is always $C$.  Case 2: One has $f(m)=m$ for all integers $m$.  Note that now the special case $b=1$ of (1) takes a particularly simple form, namely  $$ f(x)+a=f(x+a) \quad \text { for all }(x, a) \in \mathbb{Q} \times \mathbb{Z} $$  Defining $f\left(\frac{1}{2}\right)=\omega$ we proceed in three steps.  Step $A$. We show that $\omega \in\{0,1\}$.  If $\omega \leqslant 0$, we may plug $\left(\frac{1}{2},-\omega, 1-2 \omega\right)$ into (1), obtaining $0=f(0)=f\left(\frac{1}{2}\right)=\omega$. In the contrary case $\omega \geqslant 1$ we argue similarly using the triple $\left(\frac{1}{2}, \omega-1,2 \omega-1\right)$.  Step B. We show that $f(x)=\omega$ for all rational numbers $x$ with $0<x<1$.  Assume that this fails and pick some rational number $\frac{a}{b} \in(0,1)$ with minimal $b$ such that $f\left(\frac{a}{b}\right) \neq \omega$. Obviously, $\operatorname{gcd}(a, b)=1$ and $b \geqslant 2$. If $b$ is even, then $a$ has to be odd and we can substitute $\left(\frac{1}{2}, \frac{a-1}{2}, \frac{b}{2}\right)$ into (1), which yields  $$ f\left(\frac{\omega+(a-1) / 2}{b / 2}\right)=f\left(\frac{a}{b}\right) \neq \omega . $$  Recall that $0 \leqslant(a-1) / 2<b / 2$. Thus, in both cases $\omega=0$ and $\omega=1$, the left-hand part of (3) equals $\omega$ either by the minimality of $b$, or by $f(\omega)=\omega$. A contradiction.  Thus $b$ has to be odd, so $b=2 k+1$ for some $k \geqslant 1$. Applying $(1)$ to $\left(\frac{1}{2}, k, b\right)$ we get  $$ f\left(\frac{\omega+k}{b}\right)=f\left(\frac{1}{2}\right)=\omega . $$  Since $a$ and $b$ are coprime, there exist integers $r \in\{1,2, \ldots, b\}$ and $m$ such that $r a-m b=k+\omega$. Note that we actually have $1 \leqslant r<b$, since the right hand side is not a multiple of $b$. If $m$ is negative, then we have $r a-m b>b \geqslant k+\omega$, which is absurd. Similarly, $m \geqslant r$ leads to $r a-m b<b r-b r=0$, which is likewise impossible; so we must have $0 \leqslant m \leqslant r-1$.  We finally substitute $\left(\frac{k+\omega}{b}, m, r\right)$ into (1) and use (4) to learn  $$ f\left(\frac{\omega+m}{r}\right)=f\left(\frac{a}{b}\right) \neq \omega $$  But as above one may see that the left hand side has to equal $\omega$ due to the minimality of $b$. This contradiction concludes our step B.  Step C. Now notice that if $\omega=0$, then $f(x)=\lfloor x\rfloor$ holds for all rational $x$ with $0 \leqslant x<1$ and hence by (2) this even holds for all rational numbers $x$. Similarly, if $\omega=1$, then $f(x)=\lceil x\rceil$ holds for all $x \in \mathbb{Q}$. Thereby the problem is solved.  Comment 1. An alternative treatment of Steps B and C from the second case, due to the proposer, proceeds as follows. Let square brackets indicate the floor function in case $\omega=0$ and the ceiling function if $\omega=1$. We are to prove that $f(x)=[x]$ holds for all $x \in \mathbb{Q}$, and because of Step A and (2) we already know this in case $2 x \in \mathbb{Z}$. Applying (1) to $(2 x, 0,2)$ we get  $$ f(x)=f\left(\frac{f(2 x)}{2}\right) $$  and by the previous observation this yields  $$ f(x)=\left[\frac{f(2 x)}{2}\right] \quad \text { for all } x \in \mathbb{Q} $$  An easy induction now shows  $$ f(x)=\left[\frac{f\left(2^{n} x\right)}{2^{n}}\right] \quad \text { for all }(x, n) \in \mathbb{Q} \times \mathbb{Z}_{>0} $$  Now suppose first that $x$ is not an integer but can be written in the form $\frac{p}{q}$ with $p \in \mathbb{Z}$ and $q \in \mathbb{Z}_{>0}$ both being odd. Let $d$ denote the multiplicative order of 2 modulo $q$ and let $m$ be any large integer. Plugging $n=d m$ into (6) and using (2) we get  $$ f(x)=\left[\frac{f\left(2^{d m} x\right)}{2^{d m}}\right]=\left[\frac{f(x)+\left(2^{d m}-1\right) x}{2^{d m}}\right]=\left[x+\frac{f(x)-x}{2^{d m}}\right] . $$  Since $x$ is not an integer, the square bracket function is continuous at $x$; hence as $m$ tends to infinity the above fomula gives $f(x)=[x]$. To complete the argument we just need to observe that if some $y \in \mathbb{Q}$ satisfies $f(y)=[y]$, then (5) yields $f\left(\frac{y}{2}\right)=f\left(\frac{[y]}{2}\right)=\left[\frac{[y]}{2}\right]=\left[\frac{y}{2}\right]$.


Solution: Here we just give another argument for the second case of the above solution. Again we use equation (2). It follows that the set $S$ of all zeros of $f$ contains for each $x \in \mathbb{Q}$ exactly one term from the infinite sequence $\ldots, x-2, x-1, x, x+1, x+2, \ldots$.  Next we claim that  $$ \text { if }(p, q) \in \mathbb{Z} \times \mathbb{Z}_{>0} \text { and } \frac{p}{q} \in S \text {, then } \frac{p}{q+1} \in S \text { holds as well. } $$  To see this we just plug $\left(\frac{p}{q}, p, q+1\right)$ into (1), thus getting $f\left(\frac{p}{q+1}\right)=f\left(\frac{p}{q}\right)=0$.  From this we get that  $$ \text { if } x, y \in \mathbb{Q}, x>y>0 \text {, and } x \in S \text {, then } y \in S \text {. } $$  Indeed, if we write $x=\frac{p}{q}$ and $y=\frac{r}{s}$ with $p, q, r, s \in \mathbb{Z}_{>0}$, then $p s>q r$ and (7) tells us  $$ 0=f\left(\frac{p}{q}\right)=f\left(\frac{p r}{q r}\right)=f\left(\frac{p r}{q r+1}\right)=\ldots=f\left(\frac{p r}{p s}\right)=f\left(\frac{r}{s}\right) $$  Essentially the same argument also establishes that  $$ \text { if } x, y \in \mathbb{Q}, x<y<0 \text {, and } x \in S \text {, then } y \in S \text {. } $$  From (8) and (9) we get $0 \in S \subseteq(-1,+1)$ and hence the real number $\alpha=\sup (S)$ exists and satisfies $0 \leqslant \alpha \leqslant 1$.  Let us assume that we actually had $0<\alpha<1$. Note that $f(x)=0$ if $x \in(0, \alpha) \cap \mathbb{Q}$ by (8), and $f(x)=1$ if $x \in(\alpha, 1) \cap \mathbb{Q}$ by (9) and (2). Let $K$ denote the unique positive integer satisfying $K \alpha<1 \leqslant(K+1) \alpha$. The first of these two inequalities entails $\alpha<\frac{1+\alpha}{K+1}$, and thus there is a rational number $x \in\left(\alpha, \frac{1+\alpha}{K+1}\right)$. Setting $y=(K+1) x-1$ and substituting $(y, 1, K+1)$ into (1) we learn  $$ f\left(\frac{f(y)+1}{K+1}\right)=f\left(\frac{y+1}{K+1}\right)=f(x) . $$  Since $\alpha<x<1$ and $0<y<\alpha$, this simplifies to  $$ f\left(\frac{1}{K+1}\right)=1 $$  But, as $0<\frac{1}{K+1} \leqslant \alpha$, this is only possible if $\alpha=\frac{1}{K+1}$ and $f(\alpha)=1$. From this, however, we get the contradiction  $$ 0=f\left(\frac{1}{(K+1)^{2}}\right)=f\left(\frac{\alpha+0}{K+1}\right)=f\left(\frac{f(\alpha)+0}{K+1}\right)=f(\alpha)=1 $$  Thus our assumption $0<\alpha<1$ has turned out to be wrong and it follows that $\alpha \in\{0,1\}$. If $\alpha=0$, then we have $S \subseteq(-1,0]$, whence $S=(-1,0] \cap \mathbb{Q}$, which in turn yields $f(x)=\lceil x\rceil$ for all $x \in \mathbb{Q}$ due to (2). Similarly, $\alpha=1$ entails $S=[0,1) \cap \mathbb{Q}$ and $f(x)=\lfloor x\rfloor$ for all $x \in \mathbb{Q}$. Thereby the solution is complete.  Comment 2. It seems that all solutions to this problems involve some case distinction separating the constant solutions from the unbounded ones, though the "descriptions" of the cases may be different depending on the work that has been done at the beginning of the solution. For instance, these two cases can also be " $f$ is periodic on the integers" and " $f$ is not periodic on the integers". The case leading to the unbounded solutions appears to be the harder one.  In most approaches, the cases leading to the two functions $x \longmapsto\lfloor x\rfloor$ and $x \longmapsto\lceil x\rceil$ can easily be treated parallelly, but sometimes it may be useful to know that there is some symmetry in the problem interchanging these two functions. Namely, if a function $f: \mathbb{Q} \longrightarrow \mathbb{Z}$ satisfies (1), then so does the function $g: \mathbb{Q} \longrightarrow \mathbb{Z}$ defined by $g(x)=-f(-x)$ for all $x \in \mathbb{Q}$. For that reason, we could have restricted our attention to the case $\omega=0$ in the first solution and, once $\alpha \in\{0,1\}$ had been obtained, to the case $\alpha=0$ in the second solution.


Let $\nu$ be an irrational positive number, and let $m$ be a positive integer. A pair $(a, b)$ of positive integers is called good if  $$ a\lceil b \nu\rceil-b\lfloor a \nu\rfloor=m $$  A good pair $(a, b)$ is called excellent if neither of the pairs $(a-b, b)$ and $(a, b-a)$ is good. (As usual, by $\lfloor x\rfloor$ and $\lceil x\rceil$ we denote the integer numbers such that $x-1<\lfloor x\rfloor \leqslant x$ and $x \leqslant\lceil x\rceil<x+1$.)  Prove that the number of excellent pairs is equal to the sum of the positive divisors of $m$.

Solution: For positive integers $a$ and $b$, let us denote  $$ f(a, b)=a\lceil b \nu\rceil-b\lfloor a \nu\rfloor . $$  We will deal with various values of $m$; thus it is convenient to say that a pair $(a, b)$ is $m$-good or $m$-excellent if the corresponding conditions are satisfied.  To start, let us investigate how the values $f(a+b, b)$ and $f(a, b+a)$ are related to $f(a, b)$. If $\{a \nu\}+\{b \nu\}<1$, then we have $\lfloor(a+b) \nu\rfloor=\lfloor a \nu\rfloor+\lfloor b \nu\rfloor$ and $\lceil(a+b) \nu\rceil=\lceil a \nu\rceil+\lceil b \nu\rceil-1$, so  $$ f(a+b, b)=(a+b)\lceil b \nu\rceil-b(\lfloor a \nu\rfloor+\lfloor b \nu\rfloor)=f(a, b)+b(\lceil b \nu\rceil-\lfloor b \nu\rfloor)=f(a, b)+b $$  and  $$ f(a, b+a)=a(\lceil b \nu\rceil+\lceil a \nu\rceil-1)-(b+a)\lfloor a \nu\rfloor=f(a, b)+a(\lceil a \nu\rceil-1-\lfloor a \nu\rfloor)=f(a, b) . $$  Similarly, if $\{a \nu\}+\{b \nu\} \geqslant 1$ then one obtains  $$ f(a+b, b)=f(a, b) \text { and } f(a, b+a)=f(a, b)+a \text {. } $$  So, in both cases one of the numbers $f(a+b, a)$ and $f(a, b+a)$ is equal to $f(a, b)$ while the other is greater than $f(a, b)$ by one of $a$ and $b$. Thus, exactly one of the pairs $(a+b, b)$ and $(a, b+a)$ is excellent (for an appropriate value of $m$ ).  Now let us say that the pairs $(a+b, b)$ and $(a, b+a)$ are the children of the pair $(a, b)$, while this pair is their parent. Next, if a pair $(c, d)$ can be obtained from $(a, b)$ by several passings from a parent to a child, we will say that $(c, d)$ is a descendant of $(a, b)$, while $(a, b)$ is an ancestor of $(c, d)$ (a pair is neither an ancestor nor a descendant of itself). Thus each pair $(a, b)$ has two children, it has a unique parent if $a \neq b$, and no parents otherwise. Therefore, each pair of distinct positive integers has a unique ancestor of the form $(a, a)$; our aim is now to find how many $m$-excellent descendants each such pair has.  Notice now that if a pair $(a, b)$ is $m$-excellent then $\min \{a, b\} \leqslant m$. Indeed, if $a=b$ then $f(a, a)=a=m$, so the statement is valid. Otherwise, the pair $(a, b)$ is a child of some pair $\left(a^{\prime}, b^{\prime}\right)$. If $b=b^{\prime}$ and $a=a^{\prime}+b^{\prime}$, then we should have $m=f(a, b)=f\left(a^{\prime}, b^{\prime}\right)+b^{\prime}$, so $b=b^{\prime}=m-f\left(a^{\prime}, b^{\prime}\right)<m$. Similarly, if $a=a^{\prime}$ and $b=b^{\prime}+a^{\prime}$ then $a<m$.  Let us consider the set $S_{m}$ of all pairs $(a, b)$ such that $f(a, b) \leqslant m$ and $\min \{a, b\} \leqslant m$. Then all the ancestors of the elements in $S_{m}$ are again in $S_{m}$, and each element in $S_{m}$ either is of the form $(a, a)$ with $a \leqslant m$, or has a unique ancestor of this form. From the arguments above we see that all $m$-excellent pairs lie in $S_{m}$.  We claim now that the set $S_{m}$ is finite. Indeed, assume, for instance, that it contains infinitely many pairs $(c, d)$ with $d>2 m$. Such a pair is necessarily a child of $(c, d-c)$, and thus a descendant of some pair $\left(c, d^{\prime}\right)$ with $m<d^{\prime} \leqslant 2 m$. Therefore, one of the pairs $(a, b) \in S_{m}$ with $m<b \leqslant 2 m$ has infinitely many descendants in $S_{m}$, and all these descendants have the form $(a, b+k a)$ with $k$ a positive integer. Since $f(a, b+k a)$ does not decrease as $k$ grows, it becomes constant for $k \geqslant k_{0}$, where $k_{0}$ is some positive integer. This means that $\{a \nu\}+\{(b+k a) \nu\}<1$ for all $k \geqslant k_{0}$. But this yields $1>\{(b+k a) \nu\}=\left\{\left(b+k_{0} a\right) \nu\right\}+\left(k-k_{0}\right)\{a \nu\}$ for all $k>k_{0}$, which is absurd.  Similarly, one can prove that $S_{m}$ contains finitely many pairs $(c, d)$ with $c>2 m$, thus finitely many elements at all.  We are now prepared for proving the following crucial lemma.  Lemma. Consider any pair $(a, b)$ with $f(a, b) \neq m$. Then the number $g(a, b)$ of its $m$-excellent descendants is equal to the number $h(a, b)$ of ways to represent the number $t=m-f(a, b)$ as $t=k a+\ell b$ with $k$ and $\ell$ being some nonnegative integers.  Proof. We proceed by induction on the number $N$ of descendants of $(a, b)$ in $S_{m}$. If $N=0$ then clearly $g(a, b)=0$. Assume that $h(a, b)>0$; without loss of generality, we have $a \leqslant b$. Then, clearly, $m-f(a, b) \geqslant a$, so $f(a, b+a) \leqslant f(a, b)+a \leqslant m$ and $a \leqslant m$, hence $(a, b+a) \in S_{m}$ which is impossible. Thus in the base case we have $g(a, b)=h(a, b)=0$, as desired.  Now let $N>0$. Assume that $f(a+b, b)=f(a, b)+b$ and $f(a, b+a)=f(a, b)$ (the other case is similar). If $f(a, b)+b \neq m$, then by the induction hypothesis we have  $$ g(a, b)=g(a+b, b)+g(a, b+a)=h(a+b, b)+h(a, b+a) $$  Notice that both pairs $(a+b, b)$ and $(a, b+a)$ are descendants of $(a, b)$ and thus each of them has strictly less descendants in $S_{m}$ than $(a, b)$ does.  Next, each one of the $h(a+b, b)$ representations of $m-f(a+b, b)=m-b-f(a, b)$ as the sum $k^{\prime}(a+b)+\ell^{\prime} b$ provides the representation $m-f(a, b)=k a+\ell b$ with $k=k^{\prime}<k^{\prime}+\ell^{\prime}+1=\ell$. Similarly, each one of the $h(a, b+a)$ representations of $m-f(a, b+a)=m-f(a, b)$ as the sum $k^{\prime} a+\ell^{\prime}(b+a)$ provides the representation $m-f(a, b)=k a+\ell b$ with $k=k^{\prime}+\ell^{\prime} \geqslant \ell^{\prime}=\ell$. This correspondence is obviously bijective, so  $$ h(a, b)=h(a+b, b)+h(a, b+a)=g(a, b) $$  as required.  Finally, if $f(a, b)+b=m$ then $(a+b, b)$ is $m$-excellent, so $g(a, b)=1+g(a, b+a)=1+h(a, b+a)$ by the induction hypothesis. On the other hand, the number $m-f(a, b)=b$ has a representation $0 \cdot a+1 \cdot b$ and sometimes one more representation as $k a+0 \cdot b$; this last representation exists simultaneously with the representation $m-f(a, b+a)=k a+0 \cdot(b+a)$, so $h(a, b)=1+h(a, b+a)$ as well. Thus in this case the step is also proved.  Now it is easy to finish the solution. There exists a unique $m$-excellent pair of the form $(a, a)$, and each other $m$-excellent pair $(a, b)$ has a unique ancestor of the form $(x, x)$ with $x<m$. By the lemma, for every $x<m$ the number of its $m$-excellent descendants is $h(x, x)$, which is the number of ways to represent $m-f(x, x)=m-x$ as $k x+\ell x$ (with nonnegative integer $k$ and $\ell$ ). This number is 0 if $x \nmid m$, and $m / x$ otherwise. So the total number of excellent pairs is  $$ 1+\sum_{x \mid m, x<m} \frac{m}{x}=1+\sum_{d \mid m, d>1} d=\sum_{d \mid m} d $$  as required.  Comment. Let us present a sketch of an outline of a different solution. The plan is to check that the number of excellent pairs does not depend on the (irrational) number $\nu$, and to find this number for some appropriate value of $\nu$. For that, we first introduce some geometrical language. We deal only with the excellent pairs $(a, b)$ with $a \neq b$.  Part I. Given an irrational positive $\nu$, for every positive integer $n$ we introduce two integral points $F_{\nu}(n)=$ $(n,\lfloor n \nu\rfloor)$ and $C_{\nu}(n)=(n,\lceil n \nu\rceil)$ on the coordinate plane $O x y$. Then $(*)$ reads as $\left[O F_{\nu}(a) C_{\nu}(b)\right]=m / 2$; here $[\cdot]$ stands for the signed area. Next, we rewrite in these terms the condition on a pair $(a, b)$ to be excellent. Let $\ell_{\nu}, \ell_{\nu}^{+}$, and $\ell_{\nu}^{-}$be the lines determined by the equations $y=\nu x, y=\nu x+1$, and $y=\nu x-1$, respectively.  a). Firstly, we deal with all excellent pairs $(a, b)$ with $a<b$. Given some value of $a$, all the points $C$ such that $\left[O F_{\nu}(a) C\right]=m / 2$ lie on some line $f_{\nu}(a)$; if there exist any good pairs $(a, b)$ at all, this line has to contain at least one integral point, which happens exactly when $\operatorname{gcd}(a,\lfloor a \nu\rfloor) \mid m$.  Let $P_{\nu}(a)$ be the point of intersection of $\ell_{\nu}^{+}$and $f_{\nu}(a)$, and let $p_{\nu}(a)$ be its abscissa; notice that $p_{\nu}(a)$ is irrational if it is nonzero. Now, if $(a, b)$ is good, then the point $C_{\nu}(b)$ lies on $f_{\nu}(a)$, which means that the point of $f_{\nu}(a)$ with abscissa $b$ lies between $\ell_{\nu}$ and $\ell_{\nu}^{+}$and is integral. If in addition the pair $(a, b-a)$ is not good, then the point of $f_{\nu}(a)$ with abscissa $b-a$ lies above $\ell_{\nu}^{+}$(see Fig. 1). Thus, the pair $(a, b)$ with $b>a$ is excellent exactly when $p_{\nu}(a)$ lies between $b-a$ and $b$, and the point of $f_{\nu}(a)$ with abscissa $b$ is integral (which means that this point is $C_{\nu}(b)$ ).  Notice now that, if $p_{\nu}(a)>a$, then the number of excellent pairs of the form $(a, b)$ (with $b>a$ ) is $\operatorname{gcd}(a,\lfloor a \nu\rfloor)$.  ![](https://cdn.mathpix.com/cropped/2024_04_17_e0914cb4f8055c731538g-67.jpg?height=396&width=422&top_left_y=1274&top_left_x=556)  Figure 1  ![](https://cdn.mathpix.com/cropped/2024_04_17_e0914cb4f8055c731538g-67.jpg?height=431&width=442&top_left_y=1254&top_left_x=1123)  Figure 2  b). Analogously, considering the pairs $(a, b)$ with $a>b$, we fix the value of $b$, introduce the line $c_{\nu}(b)$ containing all the points $F$ with $\left[O F C_{\nu}(b)\right]=m / 2$, assume that this line contains an integral point (which means $\operatorname{gcd}(b,\lceil b \nu\rceil) \mid m$ ), and denote the common point of $c_{\nu}(b)$ and $\ell_{\nu}^{-}$by $Q_{\nu}(b)$, its abscissa being $q_{\nu}(b)$. Similarly to the previous case, we obtain that the pair $(a, b)$ is excellent exactly when $q_{\nu}(a)$ lies between $a-b$ and $a$, and the point of $c_{\nu}(b)$ with abscissa $a$ is integral (see Fig. 2). Again, if $q_{\nu}(b)>b$, then the number of excellent pairs of the form $(a, b)$ (with $a>b)$ is $\operatorname{gcd}(b,\lceil b \nu\rceil)$.  Part II, sketchy. Having obtained such a description, one may check how the number of excellent pairs changes as $\nu$ grows. (Having done that, one may find this number for one appropriate value of $\nu$; for instance, it is relatively easy to make this calculation for $\nu \in\left(1,1+\frac{1}{m}\right)$.)  Consider, for the initial value of $\nu$, some excellent pair $(a, t)$ with $a>t$. As $\nu$ grows, this pair eventually stops being excellent; this happens when the point $Q_{\nu}(t)$ passes through $F_{\nu}(a)$. At the same moment, the pair $(a+t, t)$ becomes excellent instead.  This process halts when the point $Q_{\nu}(t)$ eventually disappears, i.e. when $\nu$ passes through the ratio of the coordinates of the point $T=C_{\nu}(t)$. Hence, the point $T$ afterwards is regarded as $F_{\nu}(t)$. Thus, all the old excellent pairs of the form $(a, t)$ with $a>t$ disappear; on the other hand, the same number of excellent pairs with the first element being $t$ just appear.  Similarly, if some pair $(t, b)$ with $t<b$ is initially $\nu$-excellent, then at some moment it stops being excellent when $P_{\nu}(t)$ passes through $C_{\nu}(b)$; at the same moment, the pair $(t, b-t)$ becomes excellent. This process eventually stops when $b-t<t$. At this moment, again the second element of the pair becomes fixed, and the first one starts to increase.  These ideas can be made precise enough to show that the number of excellent pairs remains unchanged, as required.  We should warn the reader that the rigorous elaboration of Part II is technically quite involved, mostly by the reason that the set of moments when the collection of excellent pairs changes is infinite. Especially much care should be applied to the limit points of this set, which are exactly the points when the line $\ell_{\nu}$ passes through some point of the form $C_{\nu}(b)$.  The same ideas may be explained in an algebraic language instead of a geometrical one; the same technicalities remain in this way as well.