Subfield: Algebra


Question: We are given a positive integer $s \geqslant 2$. For each positive integer $k$, we define its twist $k^{\prime}$ as follows: write $k$ as $a s+b$, where $a, b$ are non-negative integers and $b<s$, then $k^{\prime}=b s+a$. For the positive integer $n$, consider the infinite sequence $d_{1}, d_{2}, \ldots$ where $d_{1}=n$ and $d_{i+1}$ is the twist of $d_{i}$ for each positive integer $i$.

Prove that this sequence contains 1 if and only if the remainder when $n$ is divided by $s^{2}-1$ is either 1 or $s$.

Solution:
First, we consider the difference $k-k^{\prime \prime}$. If $k=a s+b$ as in the problem statement, then $k^{\prime}=b s+a$. We write $a=l s+m$ with $m, l$ non-negative numbers and $m \leq s-1$. This gives $k^{\prime \prime}=m s+(b+l)$ and hence $k-k^{\prime \prime}=(a-m) s-l=l\left(s^{2}-1\right)$.

We conclude

Fact 1.1. $k \geq k^{\prime \prime}$ for every every $k \geq 1$

Fact 1.2. $s^{2}-1$ divides the difference $k-k^{\prime \prime}$.

Fact 1.2 implies that the sequences $d_{1}, d_{3}, d_{5}, \ldots$ and $d_{2}, d_{4}, d_{6}, \ldots$ are constant modulo $s^{2}-1$. Moreover, Fact 1.1 says that the sequences are (weakly) decreasing and hence eventually constant. In other words, the sequence $d_{1}, d_{2}, d_{3}, \ldots$ is 2 -periodic modulo $s^{2}-1$ (from the start) and is eventually 2-periodic.

Now, assume that some term in the sequence is equal to 1 . The next term is equal to $1^{\prime}=s$ and since the sequence is 2 -periodic from the start modulo $s^{2}-1$, we conclude that $d_{1}$ is either equal to 1 or $s$ modulo $s^{2}-1$. This proves the first implication.

To prove the other direction, assume that $d_{1}$ is congruent to 1 or $s$ modulo $s^{2}-1$. We need the observation that once one of the sequences $d_{1}, d_{3}, d_{5}, \ldots$ or $d_{2}, d_{4}, d_{6}, \ldots$ stabilises, then their value is less than $s^{2}$. This is implied by the following fact.

Fact 1.3. If $k=k^{\prime \prime}$, then $k=k^{\prime \prime}<s^{2}$.

Proof. We use the expression for $k-k^{\prime \prime}$ found before. If $k=k^{\prime \prime}$, then $l=0$, and so $k^{\prime \prime}=m s+b$. Both $m$ and $b$ are reminders after division by $s$, so they are both $\leq s-1$. This gives $k^{\prime \prime} \leq(s-1) s+(s-1)<s^{2}$.

Using Fact 1.2, it follows that the sequence $d_{1}, d_{3}, d_{5}, \ldots$ is constant to 1 or $s$ modulo $s^{2}-1$ and stabilises to 1 or $s$ by Fact 1.3. Since $s^{\prime}=1$, we conclude that the sequence contains a 1.
We make a number of initial observations. Let $k$ be a positive integer.

Fact 2.1. If $k \geq s^{2}$, then $k^{\prime}<k$.

Proof. Write $k=a s+b$, as in the problem statement. If $k \geq s^{2}$, then $a \geq s$ because $b<s$. So, $k^{\prime}=b s+a \leq(s-1) s+a \leq a s \leq a s+b=k$. Moreover, we cannot have equality since that would imply $s-1=b=0$.

Fact 2.2. If $k \leq s^{2}-1$, then $k^{\prime} \leq s^{2}-1$ and $k^{\prime \prime}=k$.



Proof. Write $k=a s+b$, as in the problem statement. If $k<s^{2}$, then it must hold $1 \leq a, b<s$, hence $k^{\prime}=b s+a<s^{2}$ and $k^{\prime \prime}=(b s+a)^{\prime}=a s+b=k$.

Fact 2.3. We have $k^{\prime} \equiv s k\left(\bmod s^{2}-1\right)\left(\right.$ or equivalently $\left.k \equiv s k^{\prime}\left(\bmod s^{2}-1\right)\right)$.

Proof. We write $k=a s+b$, as in the problem statement. Now,

$$
s k-k^{\prime}=s(a s+b)-(b s+a)=a\left(s^{2}-1\right) \equiv 0 \quad\left(\bmod s^{2}-1\right),
$$

as desired.

Combining Facts 2.1 and 2.2, we find that the sequence $d_{1}, d_{2}, d_{3} \ldots$ is eventually periodic with period 2, starting at the first value less than $s^{2}$. From Fact 2.3, it follows that

$$
k^{\prime \prime} \equiv s k^{\prime} \equiv s^{2} k \equiv k \quad\left(\bmod s^{2}-1\right)
$$

and hence the sequence is periodic modulo $s^{2}-1$ from the start with period 2 .

Now, if the sequence contains 1 , the sequence eventually alternates between 1 and $s$ since the twist of 1 is $s$ and vice versa. Using periodicity modulo $s^{2}-1$, we must have $n \equiv 1, s$ $\left(\bmod s^{2}-1\right)$. Conversely, if $n \equiv 1, s\left(\bmod s^{2}-1\right)$ then the eventual period must contain at least one value congruent to either 1 or $s$ modulo $s^{2}-1$. Since these values must be less than $s^{2}$, this implies that the sequence eventually alternates between 1 and $s$, showing that it contains a 1 .
We give an alternate proof of the direct implication: if the sequence contains a 1 , then the first term is 1 or $s$ modulo $s^{2}-1$. We prove the following fact.

Fact 3.1. For all $k \geq s^{2}$, we have $\left(k-s^{2}+1\right)^{\prime} \in\left\{k^{\prime}, k^{\prime}-s^{2}+1\right\}$.

Proof. We write $k=a s+b$, as in the problem statement. Since $k \geq s^{2}$, we have $a \geq s$. If $b<s-1$, then

$$
\left(k-s^{2}+1\right)^{\prime}=((a-s) s+(b+1))^{\prime}=(b+1) s+(a-s)=b s+a=k^{\prime} .
$$

On the other hand, if $b=s-1$, then

$$
\left(k-s^{2}+1\right)^{\prime}=((a-s+1) s+0)^{\prime}=0 s+(a-s+1)=a-s+1=k^{\prime}-s^{2}+1 .
$$

Now assume $n \geq s^{2}$ and the sequence $d_{1}, d_{2}, \ldots$ contains a 1 . Denote by $e_{1}, e_{2}, \ldots$ the sequence constructed as in the problem statement, but with initial value $e_{1}=n-s^{2}+1$. Using the above fact, we deduce that $e_{i} \equiv d_{i}\left(\bmod s^{2}-1\right)$ and $e_{i} \leq d_{i}$ for all $i \geq 1$ by induction on $i$. Hence, the sequence $e_{1}, e_{2}, \ldots$ also contains a 1 .

Since the conclusion we are trying to reach only depends on the residue of $d_{1}$ modulo $s^{2}-1$, we conclude that without loss of generality we can assume $n<s^{2}$.

Fact 2.2. If $k \leq s^{2}-1$, then $k^{\prime} \leq s^{2}-1$ and $k^{\prime \prime}=k$.


Proof. Write $k=a s+b$, as in the problem statement. If $k<s^{2}$, then it must hold $1 \leq a, b<s$, hence $k^{\prime}=b s+a<s^{2}$ and $k^{\prime \prime}=(b s+a)^{\prime}=a s+b=k$.

Using Fact 2.2, it now follows that the sequence $d_{1}, d_{2}, \ldots$ is periodic with period two. Since 1 and $s$ are twists of each other, it follows that if this sequence contains a 1, it must be alternating between 1 and $s$. Hence, $d_{1} \equiv 1, s\left(\bmod s^{2}-1\right)$ as desired.

For the other direction we can make a similar argument, observing that the second of the two cases in the proof of Fact 3.1 can only apply to finitely many terms of the sequence $d_{1}, d_{2}, d_{3}, \ldots$, allowing us to also go the other way.
First assume that $d_{k}=1$ for some $k$. Let $k$ be the smallest such index. If $k=1$ then $n=1$, so we may assume $k \geqslant 2$.

Then $d_{k-1}=a s+b$ for some non-negative integers $a, b$ satisfying $b<s$ and $b s+a=1$. The only solution is $b=0, a=1$, so $d_{k-1}=s$. So, if $k=2$, then $n=s$, so we may assume $k \geqslant 3$.

Then there exist non-negative integers $c, d$ satisfying $d_{k-2}=c s+d, d<s$ and $d s+c=s$. We have two solutions: $d=0, c=s$ and $d=1, c=0$. However, in the second case we get $d_{k-2}=1$, which contradicts the minimality of $k$. Hence, $d_{k-2}=s^{2}$. If $k=3$, then $n=d_{1}=s^{2}$, which gives remainder 1 when divided by $s^{2}-1$.

Assume now that $k \geqslant 4$. We will show that for each $m \in\{3,4, \ldots, k-1\}$ there exist $b_{1}, b_{2}, \ldots, b_{m-2} \in\{0,1, \ldots, s-1\}$ such that

$$
d_{k-m}=s^{m}-\sum_{i=1}^{m-2} b_{i}\left(s^{m-i}-s^{m-i-2}\right) \tag{9}
$$

We will prove this equality by induction on $m$. If $m=3$, then $d_{k-3}=a_{1} s+b_{1}$ for some non-negative integers $a_{1}, b_{1}$ satisfying $b_{1}<s$ and $b_{1} s+a_{1}=d_{k-2}=s^{2}$. Then $a_{1}=s^{2}-b_{1} s$, so $d_{k-3}=s^{3}-b_{1}\left(s^{2}-1\right)$, which proves (9) for $m=3$.

Assume that (9) holds for some $m$ and consider $d_{k-(m+1)}$. There exist non-negative integers $a_{m-1}, b_{m-1}$ such that $d_{k-(m+1)}=a_{m-1} s+b_{m-1}, b_{m-1}<s$ and $d_{k-m}=b_{m-1} s+a_{m-1}$. Using the inductive assumption we get

$$
a_{m-1}=d_{k-m}-b_{m-1} s=s^{m}-\sum_{i=1}^{m-2} b_{i}\left(s^{m-i}-s^{m-i-2}\right)-b_{m-1} s
$$

therefore

$$
\begin{aligned}
d_{k-(m+1)} & =a_{m-1} s+b_{m-1}=s^{m+1}-\sum_{i=1}^{m-2} b_{i}\left(s^{m-i}-s^{m-i-2}\right) s-b_{m-1} s^{2}+b_{m-1} \\
& =s^{m+1}-\sum_{i=1}^{m-1} b_{i}\left(s^{m+1-i}-s^{m-i-1}\right)
\end{aligned}
$$

which completes the proof of (9). In particular, for $m=k-1$ we get

$$
d_{1}=s^{k-1}-\sum_{i=1}^{k-3} b_{i}\left(s^{k-i-1}-s^{k-i-3}\right)
$$

The above sum is clearly divisible by $s^{2}-1$, and it is clear that the remainder of $s^{k-1}$ when divided by $s^{2}-1$ is 1 when $k$ is odd, and $s$ when $k$ is even. It follows that the remainder when $n=d_{1}$ is divided by $s^{2}-1$ is either 1 or $s$.



To prove the other implication, assume that $n$ gives remainder 1 or $s$ when divided by $s^{2}-1$. If $n \in\left\{1, s, s^{2}\right\}$, then one of the numbers $d_{1}, d_{2}$ and $d_{3}$ is 1 . We therefore assume that $n>s^{2}$. Since the reminder when a power of $s$ is divided by $s^{2}-1$ is either 1 or $s$, there exists a positive integer $m$ such that $s^{m}-n$ is non-negative and divisible by $s^{2}-1$. By our assumption $m \geqslant 3$. We also take the smallest such $m$, so that $n>s^{m-2}$. The quotient $\frac{s^{m}-n}{s^{2}-1}$ is therefore smaller than $s^{m-2}$, so there exist $b_{1}, \ldots, b_{m-2} \in\{0,1, \ldots, s-1\}$ such that $\frac{s^{m}-n}{s^{2}-1}=\sum_{i=1}^{m-2} b_{i} s^{i-1}$. It follows that

$$
n=s^{m}-\sum_{i=1}^{m-2} b_{i}\left(s^{i+1}-s^{i-1}\right)
$$

We now show that

$$
d_{j}=s^{m+1-j}-\sum_{i=1}^{m-1-j} b_{i}\left(s^{i+1}-s^{i-1}\right) \tag{10}
$$

for $j=1,2, \ldots, m-2$ by induction on $j$. For $j=1$ this follows from $d_{1}=n$. Assume now that (10) holds for some $j<m-2$. Then

$$
d_{j}=\left(s^{m-j}-\sum_{i=2}^{m-1-j} b_{i}\left(s^{i}-s^{i-2}\right)-b_{1} s\right) s+b_{1}
$$

As $d_{j}$ is positive and $b_{1} \in\{0,1, \ldots, s-1\}$, the expression $s^{m-j}-\sum_{i=2}^{m-1-j} b_{i}\left(s^{i}-s^{i-2}\right)-b_{1} s$ has to be non-negative, so we can compute the twist of $d_{j}$ as

$$
d_{j+1}=b_{1} s+s^{m-j}-\sum_{i=2}^{m-1-j} b_{i}\left(s^{i}-s^{i-2}\right)-b_{1} s=s^{m-j}-\sum_{i=1}^{m-2-j} b_{i}\left(s^{i+1}-s^{i-1}\right)
$$

which finishes the induction.

Now we use (10) for $j=m-2$ and get $d_{m-2}=s^{3}-b_{1}\left(s^{2}-1\right)=\left(s^{2}-b_{1} s\right)+b_{1}$. Then $d_{m-1}=b_{1} s+s^{2}-b_{1} s=s^{2}=s \cdot s+0, d_{m}=0 \cdot s+s=s=1 \cdot s+0$ and $d_{m+1}=0 \cdot s+1=1$.