First, start by reading the problem statement for Self-describing Sequence.
For this prelude, create an array, fr, that contains the index of each place in f(n) where f(n) changes values (that is, where the next run of identical values appears).
n 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 f(n) 1 2 2 3 3 4 4 4 5 5 5 6 6 6 6 7 fr[n] 1 2 4 6 9 12 16 ...
This array is a kind of run-length encoding of function f(n).
Input consists of a sequence of integers, one per line. The last entry is a 0, which should not be processed.
For each non-zero input value, k, print the value of n where f(n) changes to k.
7 0
16