0

A problem and solution (from a 2003 contest) are shown below. I have some questions that'll greatly help me understand the solution better:

  1. Why is the sequence $(r_i)$ purely periodic? I get that the sequence is periodic by the pigeonhole principle, but I'm not sure why if the sequence has period i, the first block of $i$ entries repeats periodically. Trying the problem for $m=3$ for instance gives the sequence $1,2,1,1,1,0,2,0,2,1,0,0$, which repeats periodically. There doesn't seem to be an obvious pattern as to the length of the period.
  2. How did the answerer know that there's an m-consecutive block $0,0,\cdots 0,1$? Why does this result from the initial block $(r_0,\cdots, r_{m-1})$?

enter image description here

  • See reinventing the wheel (cycle) here and here. Your quoted proof uses exactly the same type of argument as I do there. You may find the idea clearer in those simpler examples. – Bill Dubuque Jul 19 '22 at 09:17

1 Answers1

0

Both parts hinge on the fact that the recursion formula can be used forwards (given $x_{i+1}, x_{i+2}, \ldots ,x_{i+m}$, you can calculate $x_{i+m+1}$), which is the usual way, and backwards (given $x_{i+1}, x_{i+2}, \ldots ,x_{i+m}$, you can calculate $x_{i}$, by the formula given in the solution: $x_i=x_{i+m} - \sum_{j=1}^{m-1}x_{i+j}$).

So for 1. lets assume you have 2 identical remainder subsequences of length $m$, starting at indices $a < b$:

$$\forall j\in \{0,1,\ldots,m-1\}: r_{a+j}=r_{b+j}.$$

That's the periodic part. Because the backwards formula $x_i=x_{i+m} - \sum_{j=1}^{m-1}x_{i+j}$ does not use any division, it also applies to the remainders $r_i$. From that follows that $r_{a-1}=r_{b-1}$, because if you set $i=a-1$ and $i=b-1$ respectively in the backwards formula, you get the same values on the right hand side in each case.

That means the pair $(a,b)$ you started with as a "witness" to the periodicity of remainders subsequences of length $m$ is not the first such pair, $(a-1, b-1)$ is as well. And that goes on and on, until you finally stop at the "witness" $(0,b-a)$, which says that the subsequences of length $m$ are purely periodic.

For 2., we again use the fact that we can calculate remainders forwards and backwards. We know from 1. that at some index $d=b-a$ we have

$$\forall j\in \{0,1,\ldots,m-1\}: r_{j}=r_{d+j}.$$

What is $r_{d-1}$? We can calculate it by the backwards formula.

$$r_{d-1} \equiv r_{d-1+m} - \sum_{j=1}^{m-1}r_{d-1+j}\mod {m}$$ $$r_{d-1} \equiv r_{m-1} - \sum_{j=1}^{m-1}r_{j-1}\mod {m}$$ $$r_{d-1} \equiv x_{m-1} - \sum_{j=1}^{m-1}x_{j-1}\mod {m}$$ $$x_{m-1} - \sum_{j=1}^{m-1}x_{j-1} = 2^{m-1} - \sum_{j=1}^{m-1}2^{j-1}=1,$$

so we get $r_{d-1}=1$. The same way we get that $r_{d-m}=\ldots=r_{d-2}=0$.

From a general point, once you know that your recursion formula works forwards and backwards even with remainders, you can think of the sequence being infinite in both directions, existing for negative indices as well. Then you can calculate $r_{-1}, r_{-2}$ a.s.o. from the values $r_0,r_1$,a.s.o. That's what we did above, and we know that those remainders will come up in the actual seqeunce that has positive indices after the perdiod is over.

Ingix
  • 14,494
  • So in your answer above, it might be that some of $r_{d-m},\cdots, r_{d-2}$ are negative. In that case, can't we just extend the definition to negative indices and then just add enough multiples of $d$ to get nonnegative indices (since periodicity still holds for negative indices)? – Fred Jefferson Jul 20 '22 at 22:12
  • The $r_i$ are defined as remainders $\mod m$. Of course, you are free to choose any remainder system, but I assume if nothing is said to the contrary (which I don't see or would assume is implied), then ${0,1,\ldots,m-1}$ is used. So even if $x_i$ with negative $i$ get negative, the corresponding $r_i$ are still non-negative. You have $-2 \equiv 1 \mod 3$, for example. – Ingix Jul 21 '22 at 06:06