De-RNG-ed (Small)
Time limit5sMemory limit512 MB
Print the forced next term of K consecutive outputs from a linear generator modulo an unknown prime up to 10^D, or report that it is unknown.
- Level
Medium6 of 10
- Topics
- Brute force, Number theory, Math
- Solved
- No attempts yet
Problem
I want to build an online poker site. One important part of such a system is the random number generator. It has to be fast and random enough. Here is the compromise I came up with.
I need to generate random numbers of length at most . First I pick a prime with . Then I pick non-negative integers and . Finally I pick an integer seed with .
To print my sequence of pseudo-random numbers I first print , then update with
I print the updated as the next term of the sequence and update it again with the same formula. I repeat that as often as I want.
Do you think this is a good random number generator? Write a program that reads consecutive terms of a sequence produced this way and prints the term that comes next.
Input
The first line contains the number of test cases . The first line of each test case contains and . The next line contains consecutive terms produced by a random number generator of the kind described above.
Limits
- The given integers are consecutive terms of a sequence produced by a generator of the kind described above.
Output
For each test case print one line in the form Case #x: y, where is the test case number starting from 1.
Consider every choice of a prime and non-negative integers and that produces the given terms. If all of those choices give the same next term, then is that value. If two or more different next terms are possible, then is I don't know.