#P13479. [GCJ 2008 AMER SemiFinal] Code Sequence
[GCJ 2008 AMER SemiFinal] Code Sequence
题目描述
You are trying to compute the next number in a sequence generated by a secret code. You know that the code was generated according to the following procedure.
First, for each between and , choose a number between and (inclusive).
Then, for each integer between and (inclusive):
- Write in binary.
- Take the numbers for every bit that is set in the binary representation of . For example, when , bits and are set, so and are taken.
- Add these together, divide by , and output the remainder as .
You will be given a series of consecutive values of sequence , but you don't know at which point in the sequence your numbers begin (although you do know that there is at least one more number in the sequence), and you don't know what values of were chosen when the sequence was generated.
Find the next number in the sequence, or output UNKNOWN if this cannot be determined from the input data.
输入格式
The first line will contain an integer , the number of test cases in the input file.
For each test case, there will be:
- One line containing the integer , the number of elements of sequence that you have.
- One line containing single-space-separated integers between and , the known elements of the sequence.
输出格式
For each test case, output one line containing "Case #: " where is the number of the test case, starting from , and is the next number in the sequence, or the string UNKNOWN if the next number cannot be determined.
3
7
1 2 3 4 5 6 7
4
1 10 11 200
4
1000 1520 7520 7521
Case #1: UNKNOWN
Case #2: 201
Case #3: 3514
提示
Sample Explanation
In the first case, , and might have been , and , and the values of we have starting at . If this is correct, we don't know , so the next number in the sequence could be anything! Therefore the answer is unknown.
In the second case, we cannot know all the values of or even what is, but we can prove that in any sequence, if , , , occur in order, then the next value will always be .
Limits
Small dataset (7 Pts, Test set 1 - Visible)
Large dataset (15 Pts, Test set 2 - Hidden)