Operation: Save the Raffle Prize! (Easy)
InterviewTime limit1sMemory limit512 MB
Given a prime m and three values Seed, X1, X2, find a and c such that X1 = (a*Seed + c) mod m and X2 = (a*X1 + c) mod m.
- Level
Easy2 of 10
- Topics
- Brute force, Math, Implementation
- Solved
- No attempts yet
Problem
Apart from the input limits, there is no difference between the problems of the two difficulty levels.
Every year APC gives out raffle prizes to participants on campus. This year's raffle will be drawn with a random number generator that Junpyo wrote himself, to keep the draw 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 random number generator your brother wrote is fair?
Junpyo : Don't worry! I'm going to 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..
Junpyo's explanation, summarized briefly, is as follows.
X1 = (a × Seed + c) % m
X2 = (a × X1 + c) % m
...
Xn + 1 = (a × Xn + c) % m
In this way, random numbers are generated by the formula above from a, c, m, which Junpyo decides in secret, and Seed, which the participants decide.
Juheon : Hmm... shouldn't you be careful about how you pick a, c, m?
Junpyo : Yeah. According to the Hull-Dobell theorem, you're right. But I'm too lazy, so I'll just make m some prime I like.
Juheon : (A prime my brother likes..? Heh..)
In fact, Juheon had an ambition to win a raffle prize this year no matter what. The conversation above was the cornerstone for that. Juheon knew Junpyo so well that he already knew the prime Junpyo liked, and Junpyo was scheduled to demonstrate in front of everyone that the random number generator works properly before the actual draw, to show the participants that the generator he wrote has no problem.
Juheon hatched a scheme. During the demonstration, he will use Seed, which the participants decided, and X1, X2, which were produced from it, to recover a, c, which Junpyo decided in secret. If Juheon does not win a raffle prize, he will expose the recovered a, c, claim that everything was rigged, and invalidate the raffle itself. Juheon wants to write a program that finds a, c automatically.
Input
One line gives the prime m that Junpyo likes, the Seed the participants decided, and X1, X2 revealed by the demonstration. The input is always a feasible situation.
Output
Print the integers a, c that Junpyo chose in secret. If there are several possible answers, print any one of them.
Constraints
m ≤ 100 (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 upper 16 bits of Xn.