Let $u$ be a positive rational number and $m$ be a positive integer. Define a sequence $q_1,q_2,q_3,\dotsc$ such that $q_1=u$ and for $n\geqslant 2$:
$$\text{if }q_{n-1}=\frac{a}{b}\text{ for some relatively prime positive integers }a\text{ and }b, \text{ then }q_n=\frac{a+mb}{b+1}.$$Determine all positive integers $m$ such that the sequence $q_1,q_2,q_3,\dotsc$ is eventually periodic for any positive rational number $u$.
Remark: A sequence $x_1,x_2,x_3,\dotsc $ is eventually periodic if there are positive integers $c$ and $t$ such that $x_n=x_{n+t}$ for all $n\geqslant c$.
Proposed by Petar Nizié-Nikolac
First, we try to find a pair of positive integers $a$ and $b$ such that $\gcd(a, b) = \gcd(a + mb, b + 1) + \gcd(a + mb + m(b + 1), b + 2) = \ldots = 1$. In other words,
$$ \gcd(a + m\left(kb + \frac{k(k-1)}{2}\right), b + k) = 1 $$for all non-negative $k$. Notice that:
$$ \frac{k(k-1)}{2} = \frac{b(b+1)}{2} + \frac{1}{2}(k + b)(k - b - 1) $$So, if $m$ is even, this is just equivalent to:
$$ \gcd(a + m\left(-b^2 + \frac{b(b+1)}{2}\right), b + k) = 1 $$So, we only need to solve $a - m\frac{b(b-1)}{2} = 1$. An easy pick would be $a = b = 1$.
For even $m$, motivated by the above result, pick $u = 1$, and we use induction to prove that $q_n = \frac{m\frac{n(n-1)}{2} + 1}{n} = \frac{m}{2}(n - 1) + \frac{1}{n}$ for all $n \geq 1$. The base case is easy to check, and for induction step, notice that since $m$ is even, $\gcd(m\frac{n(n-1)}{2} + 1, n) = 1$, so we get:
$$ q_{n+1} = \frac{m\frac{n(n-1)}{2} + 1 + mn}{n + 1} = \frac{m\frac{(n+1)n}{2} + 1}{n + 1} $$Since this sequences grow unbounded, it cannot be eventually periodic.
For odd $m$, fix $a$ and $b$, let $f(k) = a + m\left(kb + \frac{k(k-1)}{2}\right)$. By parity check, exactly one of $f(0), f(2)$ is even, and similarly exactly one of $f(1), f(3)$ is even. But then it is easy to check that $\gcd(f(k), b + k) = 1$ is impossible for all $k \geq 0$, since both $f(k)$ and $b + k$ is even for some $0 \leq k \leq 3$. Furthermore, assuming $\gcd(a, b) = 1$, this narrows down to $1 \leq k \leq 3$.
For each $n \geq 1$, let $a_n$ and $b_n$ be positive integers such that $q_n = \frac{a_n}{b_n}$ and $\gcd(a_n, b_n) = 1$. Thus, $q_{n+1} = \frac{a_n + mb_n}{b_n + 1}$, and so $a_{n+1} = \frac{a_n + mb_n}{\gcd(a_n + mb_n, b_n + 1)}$ and $b_{n+1} = \frac{a_n + mb_n}{\gcd(a_n + mb_n, b_n + 1)}$. Hence, for each $n \geq 1$, $b_{n + 1}\leq b_n + 1$, and the above result implies more than that: there exists $1 \leq k \leq 3$ such that $b_{n + k} \leq \frac{b_{n + k - 1} + 1}{2}$. In particular,
$$ b_{n + 3} \leq \frac{b_n + 5}{2} $$for all $n \geq 1$. Hence, $b_n \leq 5$ for all $n$ big enough. More formal proof.Let $d_n = \max_{k \geq n}\{b_k\}$. Then, $d_{n + 3} = \max_{k \geq n + 3}\{b_k\} \leq \max_{k \geq n}\{\frac{b_k + 5}{2} \} = \frac{d_n + 5}{2}$, so by easy induction we get that $d_{3k + 1} = 5 + \frac{d_1 - 5}{2^k}$ for all $k \geq 0$, and thus $d_{3k + 1} < 6$ for $k > \log_2(\max\{d_1 - 5, 1\})$. Letting $N$ be a positive integer such that $N \equiv 1 \pmod{3}$ and $\frac{N - 1}{3} > \log_2(\max\{d_1 - 5, 1\})$, then for all $n \geq N$, $b_n \leq d_N < 6$, so $b_n \leq 5$. We are done.
Now, let $N$ be a positive integer such that $b_n \leq 5$ for all $n \geq N$. Notice that for all $n \geq N$, $a_{n + 1} \leq a_n + mb_n \leq a_n + 5m$, so by induction it is easy to see that $a_{n + k} \leq a_n + 5km$ for all $n \geq N$, $k \geq 0$. Again, the above result on $\gcd(f(k), b + k)$ means that for some $1 \leq k \leq 3$,
$$ a_{n + k} \leq \frac{a_{n + k - 1} + mb_{n + k - 1}}{2} \leq \frac{a_{n + k - 1} + 5m}{2} $$So, we can easily check that for all cases, $a_{n + 3} \leq \frac{a_n + 25m}{2}$ for all $n \geq N$.
In particular, similar to the sequence $(b_n)$, there exists $N' \geq N$ such that $a_n \leq 25m$ for all $n \geq N'$.
Thus, for $n \geq N'$, the sequence of pairs $(a_n, b_n)$ takes only finitely many values, and so is $(q_n)$. In this case, there exists $P \geq 0$ and $M \geq N'$ such that $q_M = q_{M + P}$. By small induction, since each element of the sequence $(q_n)$ is uniquely determined by the previous element (except $q_1$, which is pre-determined), $q_n = q_{n + P}$ holds for all $n \geq M$, and we are done.
First, we pick $u = 1$ for even $m$. Then, we prove by induction that $q_n = \frac{m}{2}(n - 1) + \frac{1}{n}$.
The base case $n = 1$ is trivial. For induction step, suppose that $q_n = \frac{m}{2}(n - 1) + \frac{1}{n} = \frac{\frac{m}{2}(n-1)n + 1}{n}$ for some $n$. Since $m$ is even, $\gcd(\frac{m}{2}(n-1)n + 1, n) = 1$. Hence, we get
$$ q_{n + 1} = \frac{\left(\frac{m}{2}(n-1)n + 1\right) + mn}{n + 1} = \frac{m}{2}n + \frac{1}{n + 1} $$
Thus, the sequence $q_1, q_2, \ldots$ cannot be eventually periodic, since it is unbounded. So, even values of $m$ do not satisfy the problem condition.
Now, we prove that $m$ satisfies the condition whenever it is odd. For each $n \geq 1$, let $a_n$ and $b_n$ be two relatively prime positive integers such that $q_n = \frac{a_n}{b_n}$. Also, let
$d_n = \gcd(a_n + mb_n, b_n + 1)$ for each $n \geq 1$. Note that $a_{n + 1} = \frac{a_n + mb_n}{d_n}$ and $b_{n + 1} = \frac{b_n + 1}{d_n}$.
If $d_n = d_{n + 1} = d_{n + 2} = 1$ for some positive integer $n$, then for each $1 \leq k \leq 3$,
$$ b_{n + k} = b_{n + k - 1} + 1, a_{n + k} = a_{n + k - 1} + mb_{n + k - 1} $$Small induction implies $b_{n + k} = b_n + k$ and $a_{n + k} = a_n + m\frac{k(k - 1)}{2}$.
Now,
$$ a_{n + k} = a_n + m\frac{k(k - 1)}{2} \equiv a_n + s \pmod{2} $$where $s = 0$ if $4 | k$ or $4 | k - 1$, and $s = 1$ otherwise. Checking all combinations with $b_{n + k} = b_n + k$, at least one pair of $(a_{n+k}, b_{n+k})$ for $k = 0, 1, 2, 3$ has both its elements even, which is a contradiction.
Hence, for all $n \geq 1$, there exists $0 \leq k \leq 2$ such that $d_{n + k} > 1$. In particular, there exists infinitely many $n \geq 1$ such that $d_n > 1$
Let $1 < t_1 < t_2 < \ldots$ be all the positive integers such that $d_{t_i - 1} > 1$. By our result above, $t_{i + 1} \leq t_i + 3$ for all $i \geq 1$. Notice that:
$$ b_{t_{i + 1}} \leq \frac{b_{t_{i + 1} - 1} + 1}{2} \leq \frac{b_{t_i} + 3}{2} $$So, $b_{t_{i + 1}} - 3 \leq \frac{b_{t_i} - 3}{2}$. Since $(b_{t_i})$ is an integer sequence, this implies that there exists a positive integer $N$ such that $b_{t_i} \leq 3$ for all $i \geq N$.
Next, notice that for each $n \geq t_N$, there exists a positive integer $i \geq N$ and a non-negative integer $k < 3$ such that $n = t_i + k$. So, $b_n = b_{t_i} + k \leq 3 + 2 = 5$.
Now, for each $n \geq t_N$, consider that
$$ a_{n + 1} \leq a_n + mb_n \leq a_n + 5m $$Then, for each $i \geq N$, consider that
$$ a_{t_{i + 1}} \leq \frac{a_{t_{i + 1} - 1} + mb_{t_{i + 1} - 1}}{2} \leq \frac{a_{t_{i + 1} - 1} + 5m}{2} \leq \frac{a_{t_i} + 15m}{2} $$Similar to above, we obtain that there exists $N' \geq N$ such that $a_{t_i} \leq 15m$ for all $i \geq N'$.
For each $n \geq t_{N'}$, writing $n = t_i + k$ for some $0 \leq k < 3$ and $i \geq N'$ as above, we find $a_n \leq a_{t_i} + 5km \leq 15m + 10m = 25m$.
Hence, for all $n \geq t_{N'}$, $a_n \leq 25m$ and $b_n \leq 3$. So, there exists positive integers $M \geq t_{N'}$ and $K \leq 75m$ such that $(a_M, b_M) = (a_{M + K}, b_{M + K})$. Since the value of $q_n = \frac{a_n}{b_n}$ uniquely determines $q_{n + 1} = \frac{a_{n+1}}{b_{n+1}}$ for each $n \geq 1$, we deduce that $q_n = q_{n + K}$ for all $n \geq M$, and so $(q_n)$ is eventually periodic,
Furthermore, we might be interested in finding all such periodic sequences for all suitable values of $m$, ignoring the first few elements. Also, we could be interested in finding how fast the sequence becomes periodic.
One obvious solution is $(m, m, m, \ldots)$, which is the unique solution for the case $(b_n)$ is constant.
Some other solutions found are $\left( \frac{5m}{2}, \frac{7m}{3}, \frac{5m}{2}, \ldots \right)$, $\left( \frac{7m}{3}, \frac{5m}{2}, \frac{7m}{3}, \ldots \right)$, $\left( 2m, \frac{3m}{2}, \frac{5m}{3}, 2m, \ldots \right)$, both assumeing $3 \nmid m$.
If $(b_n)$ is constant, we get that $b_{n + 1} | b_n + 1$ implies $b_n = 1$ for all $n$. But then this simply means $a_{k + 1} = \frac{a_k + m}{2}$ for all $k \geq 1$, for which the only integer sequence $(a_n)$ satisfying it is the constant sequence of $m$s, and thus we get $\boxed{q_n = m \; \forall n \geq 1}$.
Assuming $(b_n)$ is periodic, we may assume that $b_n \leq 5$ for all $n \geq 1$. Now, we will prove that in fact, $b_n \leq 3$ for all $n$ large enough. Note that $b_{n + 1} | b_n + 1$ and $b_{n + 3} < b_n + 3$ for all $n \geq 1$.
Proof.First, assume that $b_n \geq 3$ for all $n \geq 1$. It is easy to check that the sequence $(b_n)$ is $3$-periodic using the above property and it is either $(3, 4, 5, ...)$, $(4, 5, 3, ...)$, or $(5, 3, 4, ...)$. WLOG assume $b_1 = 3$. Then, $b_n$ equals $3$ if $n \equiv 1 \pmod{3}$, $4$ if $n \equiv 2 \pmod{3}$, and $5$ if $n \equiv 0 \pmod{3}$. Now, this means for all $k \geq 0$,
\begin{align*}
a_{3k + 2} &= a_{3k + 1} + 3m \\
a_{3k + 3} &= a_{3k + 2} + 4m \\
a_{3k + 4} &= \frac{a_{3k + 3} + 5m}{2} \\
&= \frac{a_{3k + 1} + 12m}{2}
\end{align*}Then, $a_{3k + 4} - 12m = \frac{a_{3k + 1} - 12m}{2}$ for all $k \geq 0$. By easy induction,
$$ a_{3k + 1} = \frac{1}{2^k} (a_1 - 12m) $$Since the sequence $(a_n)$ consists of integers, this is possible if and only if $a_1 = 12m$. But then $\gcd(a_1, b_1) = \gcd(12m, 3) = 3 > 1$, a contradiction.
Now, consider a positive integer $N$ such that $b_N \leq 2$. We claim that $b_n \leq 3$ for all $n \geq N$. Suppose not, and let $K$ be the smallest positive integer with $K \geq N$ such that $b_K \geq 4$. It is easy to see that $K \geq N + 2$. Since $4 \leq b_K \leq b_{K - 1} + 1 \leq 4$, then $b_K = 4$ and $b_{K - 1} = 3$. Then, $b_{K - 2} = 2$ because $3 | b_{K - 2} + 1$ and $b_{K - 2} \leq 3$. But then, $a_{K - 2}$ is odd, and so $a_K = a_{K - 1} + 3m = a_{K - 2} + 5m$ is even. A contradiction (since $b_K$ is also even).
If $b_n \geq 2$ for all $n \geq 1$, then it is easy to show that the sequence $(b_n)$ must be $2$-periodic with values alternating between $2$ and $3$. WLOG suppose $b_1 = 2$. Then, $b_{2k + 1} = 2$ and $b_{2k + 2} = 3$ for each $k \geq 0$. By small calculations, for each $k \geq 0$,
$$ a_{2k + 3} = \frac{a_{2k + 2} + 3m}{2} = \frac{a_{2k + 1} + 5m}{2} $$Applying the same trick, we get that $a_{2k + 3} = 5m$ for all $k$, and this gives us the sequence
$$\boxed{\left( \frac{5m}{2}, \frac{7m}{3}, \frac{5m}{2}, \ldots \right)}$$and
$$\boxed{\left( \frac{7m}{3}, \frac{5m}{2}, \frac{7m}{3}, \ldots \right)}$$So, now suppose that $b_n = 1$ for some $n \geq 1$. Due to periodicity, $b_n = 1$ for infinitely many $n$.
Note that the integers $t_i$ from the formal solution are precisely those for which $b_n < b_{n - 1} + 1$. Consider a sequence $u_1 < u_2 < \ldots$ such that $b_{u_i} = 1$ for all $i$. It can be checked that the sequence $(u_i)$ is a subsequence of $(t_i)$.
We continue by showing that $a_{t_n} \leq 6m$ for all $n$ big enough.
ProofConsider all the possibilities for the pair $(a_{t_{n + 1}}, b_{t_{n + 1}})$.
For sake of writing, let $a = a_{t_n}$, and let $k = t_{n + 1} - t_n$.
If $k = 1$, then $a_{t_{n + 1}} \leq \frac{a + m b_{t_n}}{2} \leq \frac{a + 3m}{2}$.
If $k = 2$, then $a_{t_{n + 1}} \leq \frac{a + m (2b_{t_n} + 1)}{2} \leq \frac{a + 5m}{2}$ since $b_{t_n} = b_{t_n + 1} - 1 \leq 2$.
If $k = 3$, then $b_{t_n} = 1$ and thus $a_{t_{n + 1}} \leq \frac{a + 6m}{2}$
Either way, $a_{t_{n + 1}} \leq \frac{a_{t_n} + 6m}{2}$ for all $n \geq 1$. Using the same finishing line as the previous result, we get $a_{t_n} \leq 6m$ for all $n$ big enough.
More results that have not been proved here: For every $n$ large enough, $a_n \leq \frac{5m}{2}$ if $b_n = 1$, $a_n \leq 5m$ if $b_n = 2$, and $a_n \leq 7m$ if $b_n = 3$.
Sadly, this is the best bound I could go with, and probably I cannot make any further progress (I tested it with a C++ program and apparently $a_n$ could be very close to $7m$ for some input.)
Beautiful problem despite even $m$ not working for such small portion of cases.
It can be proven that the sequence will be eventually periodic for all even $m$ if and only if the expression $|a_k-\frac{m \cdot b_k(b_k-1)}{2}|$ is never equal to $1$, that is, for all positive integers $k$, where $a_k$ and $b_k$ are denominator and numerator of k-th $u$ whose denominator and numerator share a common divisor greater than 1 (including $u_1$, no matter if it’s denominator and numerator share a prime factor), after they get divided by their $gcd$.
really sketchy sketch
what we will do is if we let $q_n = a_n/b_n$ for each $n$ in lowest terms, we will show that $b_n$ is bounded, and that similarly, $a_n$ is bounded. One can see that even $m$ do not work; letting $u = 1$ and we can induct to get $q_n = \tfrac{m}{2}(n-1) + \tfrac{1}{n}$. This sequence can never be periodic since the denominator is unbounded. Even $m$ are bad.
For odd $m$, we can do some work to get that there do not exist consecutive $b_i \to b_{i+3}$ that are all increasing, where there must be a $/2$ cut somewhere in the middle. Hence, $b_i$ is bounded.
For convenience$,$ let $q_n=\frac{a_n}{b_n}$ (in lowest terms) for all $n.$ First$,$ we prove that even $m$ do not work$.$ Let $m=2k.$ We will search for a quadratic polynomial $f,$ such that $\gcd(b, f(b))=1$ for all $b$ and if some $q_n$ is of the form $\frac{f(b_n)}{b_n},$ then $q_{n+1}$ is of the form $\frac{f(b_{n+1})}{b_{n+1}}$ (note that because of the $\gcd$ property of the polynomial$,$ the fractions are in lowest terms)$.$ We must certainly have $b_{n+1}=b_n+1$ and $$f(b_n+1)-f(b_n)=mb_n.$$The last equation forces the polynomial to be exactly $f(x)=kx^2-kx+c,$ and we decide to choose $c=1,$ so that $\gcd(b, f(b))=1$ indeed$.$ It is now evident that for all $n,$ $$q_{n}=\frac{f(b_n)}{b_n},$$and so $b_n$ grows unboundedly$,$ thus the sequence is never periodic$.$
Now suppose that $m$ is odd$.$ We examine some term $q_n$ and track how the parities of the numerator and denominator of the following term change$.$ Note that $e$ denotes an even number$,$ and $o$ denotes an odd one$.$ The following diagram is therefore true$:$ $$\frac{e}{o} \rightarrow \frac{o}{e} \rightarrow \frac{o}{o} \rightarrow \frac{e}{e}$$So if we start with some $q_n,$ in the following three terms$,$ namely $q_{n+1}, q_{n+2}$ and $q_{n+3}$ there will be a cancelation$.$ Therefore one of the corresponding denominators will be at most $\frac{b_n+3}{2}.$ With this observation$,$ and after looking at the appropriate subsequence$,$ we can WLOG suppose that $b_1\leq 6,$ and in fact$,$ that also $b_n\leq 6$ for all $n.$ In a similar way$,$ we see that the numerators must also be bounded (because of the mentioned cancelation$,$ one of $a_{n+1}, a_{n+2}$ and $a_{n+3}$ must be at most $\frac{1}{2}a_n+C,$ with $C$ being some constant)$.$ Therefore if $a_n\leq 2C$ for some $n$ (we choose $C$ appropriately)$,$ one of the next three terms in the sequence $\{a_i\}_{i=1}^{\infty}$ is also bounded by $2C.$ But that means that we have found an infinite subsequence $\{q_{i_j}\}_{j=1}^{\infty} \subseteq \{q_n\}_{n=1}^{\infty},$ such that for all $j,$ the sum $a_{i_j}+b_{i_j}$ is bounded$.$ However$,$ there is only a finite number of choices for $a_{i_j}$ and $b_{i_j},$ so there must be two equal terms $q_{i_u}=q_{i_v}$ with $u\neq v$ $.$ But each $q_n$ is uniquely determined by the previous term$,$ therefore the sequence is periodic$.$ $\blacksquare$