Operation Protect the Lottery Prize! (Normal)
InterviewTime limit1sMemory limit512 MB
Given a prime m and three values Seed, X1, X2 with X1 = (a*Seed+c) mod m and X2 = (a*X1+c) mod m, find any valid a and c.
- Level
Easy3 of 10
- Topics
- Math, Number theory, Implementation
- Solved
- No attempts yet
Problem
Apart from the input constraints, there is no difference between the difficulty versions of this problem.
APC gives out lottery prizes to participants on campus every year. This year's lottery will be drawn using a random number generator that Junpyo wrote himself, so that the draw is fair. A random number generator is a device that produces a sequence of numbers or symbols that cannot be predicted any further in theory.
Juheon: How do you know the generator you wrote is fair?
Junpyo: Don't worry! I'll implement the 'Linear Congruential' method, which is the ANSI standard in C ~
Juheon: What's the linear congruential method?
Junpyo: Well, it goes like this..
To summarize Junpyo's explanation,
X1 = (a × Seed + c) % m
X2 = (a × X1 + c) % m
...
Xn + 1 = (a × Xn + c) % m
In other words, random numbers are generated by the formula above from a, c, m, which Junpyo picks secretly, and the Seed value, which the participants pick.
Juheon: Hmm... shouldn't a, c, m not be chosen arbitrarily?
Junpyo: Right. According to the Hull-Dobell theorem, that's correct. But I'm too lazy, so I'll just make m some prime I like.
Juheon: (A prime hyung likes..? Heh..)
Juheon actually had an ambition to win a lottery prize this year no matter what! The conversation above was the foundation for that! Juheon knew Junpyo so well that he already knew the prime Junpyo liked, and to show the participants that the generator Junpyo wrote had no problems, Junpyo was scheduled to demonstrate in front of everyone that the generator works well before the actual draw.
Juheon devised a scheme. During the demonstration, using the Seed chosen by the participants and the X1, X2 produced from it, Juheon will find the a, c that Junpyo secretly chose. If Juheon does not win a lottery prize, he plans to expose the a, c he found, claim that everything was rigged, and invalidate the draw itself! Juheon wants to write a program that finds a, c automatically.
Input
One line gives the prime m that Junpyo likes, the Seed chosen by the participants, and the X1, X2 revealed by the demonstration. The input is always a possible situation.
Output
Print the integers a, c that Junpyo secretly selected. If there are multiple possible answers, print any one of them.
Constraints
m ≤ 100,000 (m is prime)
0 < Seed, X1, X2 < m
0 ≤ a, c < m
Hint
The rand() function in C is similar to the above, but it is implemented to return the top 16 bits of Xn.