#P13479. [GCJ 2008 AMER SemiFinal] Code Sequence

[GCJ 2008 AMER SemiFinal] Code Sequence

题目描述

You are trying to compute the next number in a sequence SnS_n generated by a secret code. You know that the code was generated according to the following procedure.

First, for each kk between 00 and 2929, choose a number CkC_k between 00 and 1000610006 (inclusive).

Then, for each integer nn between 00 and 1 000 000 0001\ 000\ 000\ 000 (inclusive):

  • Write nn in binary.
  • Take the numbers CkC_k for every bit kk that is set in the binary representation of nn. For example, when n=5n=5, bits 00 and 22 are set, so C0C_0 and C2C_2 are taken.
  • Add these CkC_k together, divide by 1000710007, and output the remainder as SnS_n.

You will be given a series of consecutive values of sequence SS, 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 CkC_k 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 TT, the number of test cases in the input file.

For each test case, there will be:

  • One line containing the integer NN, the number of elements of sequence SS that you have.
  • One line containing NN single-space-separated integers between 00 and 1000610006, the known elements of the sequence.

输出格式

For each test case, output one line containing "Case #XX: YY" where XX is the number of the test case, starting from 11, and YY 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, C0C_0, C1C_1 and C2C_2 might have been 11, 22 and 44, and the values of SnS_n we have starting at n=1n=1. If this is correct, we don't know C3C_3, 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 CkC_k or even what nn is, but we can prove that in any sequence, if 11, 1010, 1111, 200200 occur in order, then the next value will always be 201201.

Limits

  • 1T201 \leqslant T \leqslant 20

Small dataset (7 Pts, Test set 1 - Visible)

  • 1N51 \leqslant N \leqslant 5

Large dataset (15 Pts, Test set 2 - Hidden)

  • 1N10001 \leqslant N \leqslant 1000