Number Theory – Analyze Sequences of the Form A(n) = A(A(n-1) mod n)^2

elementary-number-theorymodular arithmeticrecurrence-relations

$$A(0)= x \in\mathbb{Z}^+,\ A(n) = A(A(n-1) \bmod n)^2$$
At first glance, one would think that such sequence would grow very fast. But my testing suggest that this sequence actually ends with $x^4$ repeating indefinitely. To make testing faster, i set $B(n) = log_x(A(n))$.
$$B(0) = 1$$
$$B(n) = 2B(x^{B(n-1)}\bmod n)$$
Another finding is that the repetition starts at $n=x^4+1$ for all the tested values of $x$. Can anybody prove that this will happen for all starting values?

Best Answer

Let $P := \{1, x, x^2, x^3, x^4\}$. The proof relies on noticing that $$\begin{align} A(n) = x &\iff n = 0 \\ A(n) = x^2 &\iff n \in P \\ x^4 \mid A(n) &\iff n \notin P \cup \{0\} \end{align}$$

First, it is not hard to deduce the first equation, because in the recurrence we have a square. This also means that $$ \forall n \geq 1, \quad x^2 \mid A(n), $$ and more generally, $$ \forall n \geq 1, \exists k \geq 1 \quad A(n) = x^{2^k}. \tag{1} $$

For $n \in \{1,\ldots, x^4\} \setminus P$, we have $n \nmid A(n-1)$ because $A(n-1)$ is a power of $x$ and $n$ is not. So $N := A(n-1) \bmod n \geq 1$. This means, by $(1)$, there is $k\geq1$ such that $$ A(n) = A(N)^2 = (x^{2^k})^2 = x^{2^{k+1}} $$ which implies $$ \forall n \in \{1,\ldots, x^4\} \setminus P, \quad x^4 \mid A(n). \tag{2} $$ If $n \in P$, then $n-1 \notin P$. By $(2)$ This means $x^4 \mid A(n-1)$ which implies $n \mid A(n-1)$ (because $n \mid x^4$). So $$ A(n) = A(A(n-1) \bmod n)^2 = A(0)^2 = x^2. $$ In other words, $$ \forall n \in P, \quad A(n) = x^2. \tag{3} $$


Now we are able to prove the full statement by induction, that is for $k \geq 1$, $A(x^4+k) = x^4$. At $k=1$, we have by $(3)$ ($x^2 \in P$) $$ A(x^4+1) = A(A(x^4) \bmod x^4+1)^2 = A(x^2)^2 = x^4. $$ Suppose the property true for some $k \geq 1$, then by $(3)$ ($x^4 \in P$) $$ A(x^4+k+1) = A(A(x^4+k) \bmod x^4 + k +1)^2 = A(x^4)^2 = x^4. $$ The property holds for $k+1$, which complete the induction.

Related Question