#P13403. [GCJ 2010 #3] De-RNG-ed

    ID: 15272 远端评测题 3000ms 1024MiB 尝试: 0 已通过: 0 难度: 4 上传者: 标签>2010数论扩展欧几里德算法分类讨论Google Code Jam

[GCJ 2010 #3] De-RNG-ed

题目描述

I want to make an online poker website. A very important component of such a system is the random number generator. It needs to be fast and random enough. Here is a compromise I came up with. I need a way to generate random numbers of length at most DD. My plan is to select a prime number P10DP \leq 10^D. I am also going to pick non-negative integers AA and BB. Finally, I'm going to pick an integer seed SS between 00 and P1P-1, inclusive.

To output my sequence of pseudo-random numbers, I'm going to first output SS and then compute the new value of SS like this:

S:=(A×S+B)modPS := (A\times S + B) \bmod P

Then I will output the new value of SS as the next number in the sequence and update SS again by using the same formula. I can repeat this as many times as I want.

Do you think that this is a good random number generator? Can you write a program that takes KK consecutive elements of a sequence that was generated by my random number generator, and prints the next element of the sequence?

输入格式

The first line of the input gives the number of test cases, TT. TT test cases follow. Each one starts with a line containing DD and KK. The next line contains KK consecutive elements generated by a random number generator of the kind described above.

输出格式

For each test case, output one line containing "Case #xx: yy", where xx is the case number (starting from 1) and yy is either the next number in the sequence, or the string "I don't know." if the answer is ambiguous.

3
2 10
0 1 2 3 4 5 6 7 8 9
3 1
13
1 5
6 6 6 6 6
Case #1: 10
Case #2: I don't know.
Case #3: 6

提示

Limits

  • 1T1001 \leq T \leq 100.
  • 1K101 \leq K \leq 10.
  • The KK integers will be consecutive elements of a sequence generated by a random number generator of the type described above.

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

  • 1D41 \leq D \leq 4.

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

  • 1D61 \leq D \leq 6.