Given consecutive terms of a binary-additive sequence with unknown coefficients, output the next term or UNKNOWN if it is not forced.
Hard8MathBit manipulationNumber theoryNo attempts yetTime limit5sMemory limit512 MBA sequence S is generated from a secret code, and you have to work out its next term. The code was built as follows.
First, for each k from 0 to 29, a number Ck between 0 and 10006 inclusive was chosen.
Then, for every integer n from 0 to 109 inclusive:
You are given several consecutive terms of S. You do not know where in the sequence they start, though you do know that at least one more term follows them, and you do not know which Ck were chosen.
Print the term that comes right after the given ones. If the input does not pin it down to a single value, print UNKNOWN.
The first line contains the number of test cases T.
Each test case takes two lines.
Limits
For each test case print one line in the form Case #X: Y, where X is the test case number starting from 1 and Y is the next term. Write UNKNOWN in place of Y when the next term is not determined.
In the first test case of the sample input, C0,C1,C2 could have been 1, 2 and 4, with the given terms starting at n=1. Read that way, C3 is unknown, so the next term could be anything and the answer is UNKNOWN.
In the second test case neither the full list of Ck nor the starting index can be recovered. Even so, whenever 1, 10, 11, 200 occur consecutively in this order, the next value is always 201.