5. The sequence of real numbers $\left(a_{k}\right)_{k=1}^{\infty}$ satisfies for every index $k \geqq 1$ the equation

$$
a_{k+1}=3 a_{k}-\left\lfloor 2 a_{k}\right\rfloor-\left\lfloor a_{k}\right\rfloor .
$$

Determine all natural numbers $n$ for which such a sequence with the first term $a_{1}=1 / n$ is constant from a certain term onwards.

(The notation $\lfloor x\rfloor$ denotes the greatest integer not exceeding the given real number $x$.) (Jaromír Šimša)
SOLUTION. Let's introduce the function $f(x)=3 x-\lfloor 2 x\rfloor-\lfloor x\rfloor$. The sequence in question is then determined by the term $a_{1}$ and the rule $a_{k+1}=f\left(a_{k}\right)$. Therefore, from the obvious equalities $f(1)=f(0)=0$ and $f(1 / 2)=1 / 2$, it follows that this sequence is constant from some term onwards if the number 1 or $1 / 2$ is present in it.

Since on the interval $0<x<1 / 2$ we have $f(x)=3 x$, the presence of the number 1, resp. $1 / 2$ in our sequence of numbers $a_{k}$ is guaranteed if $a_{1}=1 / 3^{\alpha}$, resp. $a_{1}=1 /\left(2 \cdot 3^{\alpha}\right)$, where $\alpha$ denotes (here and throughout) a non-negative integer. Thus, we see that among the sought natural numbers $n$ are all values $n=3^{\alpha}$ and $n=2 \cdot 3^{\alpha}$. In the remainder of the solution, we will show that no other suitable $n$ exist.

For this, it will suffice to find for each suitable $n$ an $\alpha$ with the property $n \mid 2 \cdot 3^{\alpha}$. Fix one suitable $n$ and, in addition to the sequence $\left(a_{k}\right)$ with the first term $a_{1}=1 / n$, consider a new sequence $\left(b_{k}\right)$ with terms $b_{k}=n \cdot a_{k}$. Then $b_{1}=1$ and the recurrence relation $a_{k+1}=f\left(a_{k}\right)$, when multiplied by the number $n$, becomes

$$
b_{k+1}=3 b_{k}-n\left\lfloor\frac{2 b_{k}}{n}\right\rfloor-n\left\lfloor\frac{b_{k}}{n}\right\rfloor
$$

From this, by induction, it follows that each number $b_{k}$ is an integer and, moreover, the congruence (here and in the next paragraph modulo $n$) $b_{k+1} \equiv 3 b_{k}$ holds, from which (again by induction) $b_{k} \equiv 3^{k-1}$ for each $k$.

Since $n$ is suitable, the sequence $\left(a_{k}\right)$ is constant from some term onwards, so the same is true for the sequence $\left(b_{k}\right)$. For some $\alpha$ we then have $b_{\alpha+2}=b_{\alpha+1}$, which together with $b_{\alpha+2} \equiv 3 b_{\alpha+1}$ leads to $2 b_{\alpha+1} \equiv 0$. Together with $b_{\alpha+1} \equiv 3^{\alpha}$, we already get $2 \cdot 3^{\alpha} \equiv 0$ or $n \mid 2 \cdot 3^{\alpha}$, as we promised to show.

Conclusion. The sought numbers $n$ are precisely of the form $n=3^{\alpha}$ and $n=2 \cdot 3^{\alpha}$, where $\alpha$ is a non-negative integer.