Look-and-Say sequences |
For instance, if x1 (the first term of the sequence) is 1, the next term is the description of this term, 11 ("one 1"), which is described by 21 ("two 1's"), which is described by 1211 ("one 2 one 1"), etc.; the series continues 111221, 312211, 13112221, ...
Your problem is to build a program that, given the first term of a look-and-say sequence x1, calculates the j-th digit of the i-th term, xi.
Each line in the input corresponds to a test case specified by 3 integer values: x1, i and j, with 1x11000, 1i1000 and 1jmin(log10(xi) + 1, 1000). The end of the input is indicated by a line ``0 0 0''.
For each test case, the program must output a line with the j-th digit of the term xi of the look-and-say sequence that starts with the term x1.
1 3 1 1 3 2 1 7 2 123 3 1 0 0 0
2 1 3 3