Recovering a Linear Congruential Sequence
Time limit2sMemory limit128 MB
Given odd-indexed terms of a hidden linear congruential generator mod 10001, find (a,b) and output the even-indexed terms forming the lexicographically smallest valid sequence.
- Level
Medium6 of 10
- Topics
- Math, Number theory, Brute force
- Solved
- No attempts yet
Problem
A contest organizer builds their judge data with a linear congruential generator. First they choose three integers , , and , each between and inclusive. Then, for , the remaining values are produced by the recurrence
In the resulting sequence, the odd-indexed values are used as input data and the even-indexed values are used as output data.
You are given the input data . Recover output data for which some pair is consistent with every given value. Because more than one may be consistent, output the sequence that is lexicographically smallest among all consistent sequences.
Input
The first line contains ().
Each of the next lines contains on its -th line ().
Every input is data that was actually produced by the process above, so at least one consistent pair is guaranteed to exist.
Output
Print lines. The -th line contains . The whole output sequence must be the lexicographically smallest one among all sequences consistent with the given input.