We shall prove a more general statement. That is, we prove that xn is a-periodic modulo m, for each m. In doing so, we need the following lemmas.
Lemma 1. Let m≥3 be an integer which is not a power of 2. Let x1 be a fixed positive integer and yn be a sequence of positive integers such that xn+1=xnyn+1, n=1,…. If the sequence xn is eventually periodic mod m then there are positive integers b,d,T where 2≤d≤m−1 such that yb+kT,k=0,1,… is periodic mod d.
Proof. Since m is not a power of two it would have an odd prime divisor, say p. Since the sequence xn(modm) is eventually periodic it follows that xn(modp) is also eventually periodic. Hence, for all large n, xn+T−xn is divisible by p. Fix b, large enough such that a≡xb(modp) and a=0,1. Since p≥3, such a b exists because each 0(modp) followed by 1 which is followed by 2. Clearly xb+kT≡a(modp) for each a≥0. Notice that p divides ayb+kT−ayb. Hence, ∣yb+kT−yb∣ is divisible by the order of a mod p, namely d. That is, yb+kT(modd) is periodic. As desired.
Now, we shall prove a nice fact about the periodicity of S(b+kT), k=0,…
Lemma 2. Let b,T,d be positive integers, if the sequence S(b+kT), k=0,… is constant mod d then d divides T and d∈{1,3,9}.
Proof. Letting k=10rs for some large enough r it follows that S(b+10rsT)=S(b)+S(sT)≡S(b)(modd). Whence, S(sT)≡0(modd). We can also assume gcd(10,T)=1 indeed, if T=2α5βT1, gcd(T1,10)=1 then, by a suitable choice of s we can make power of 10.
Then, there are s0,s1 such that
Ts0≡1(mod100)
and
Ts1≡9(mod10r+1).
Further, by a suitable choice of r we can ensure that Ts0<10r. It follows that
S((s0+s1)T)=S(s0T)+S(s1T)−9.
Since d divides S(s0T), S(s1T), S((s0+s1)T) it follows that d divides 9. That is, S((s0+s1)T). And since S(sT)≡sT(mod9) it follows that sT≡0(modd), Hence, d divides T. This completes our proof.
Back to our problem. We shall firstly prove that m has no odd prime divisor. Assume the sequence is periodic with the minimal period of T. Since there are infinitely many i such that S(i) is divisible by p−1 if p divides xi then xi+2≡2(modp). If p doesn't divide xi then xi+1≡2(modp). Hence, 2 is among the residues of xn modulo p. Take a=2 in the first lemma. It follows that the sequence S(kT+i) is constant modulo the order of 2 modulo p, namely d. Hence, d divides 9. That is, p divides 29−1=7×73. If p=7 then for i≡0(mod3) we have xi+1≡2(mod7) and xi+2≡3(mod7) since the order of 3 mod 7 is 6 we reached to a contradiction. The same holds for the case i≡1(mod3). Finally, for i≡2(mod3) we have xi+1≡5(mod7) and since the order of 5 modulo 7 is 6 we again reached to a contradiction.
If p=73 the numbers with orders that dividing 9 are
1,2,4,8,16,32,64,55,37,
surprisingly powers of 2. If i is divisible by 9 then xi+1≡2(mod73) and xi+2≡3(mod73) while the order of 3 modulo 73 doesn't divide 9. If i is not divisible by 9 then xi+1 is not congruent to a power of 2 mod 73. Hence, its order modulo 73 doesn't divide 9.
Finally, for powers of 2 we prove that the only solutions are m=1,2,4. Let m=2c we claim that the period is of the form 1,2,1,2,…. Indeed if xi is odd then since the order of xi modulo 2c is a power of two and for sake of periodicity it must divide 9 we would obtain that xi≡1(mod2c). Hence, xi+1≡2(mod2c) and by the same argument xi+2k≡2S(i−1+2k)+1≡1(mod2c) yielding S(i−1+2k)≥c for all k. Thus, c≤minS(i−1+2k)=2. Whence, m=1,2,4. ■