#P2044. [NOI2012] 随机数生成器
[NOI2012] 随机数生成器
Description
Dongdong has recently become fascinated with randomized algorithms, and random numbers are the foundation for generating them. He plans to use the Linear Congruential Method to generate a sequence of random numbers. This method requires setting four non-negative integer parameters , and generates a sequence according to the formula:
Here, denotes the remainder when the preceding number is divided by . From this equation, we can see that the next number in the sequence is always determined by the previous one.
Sequences generated by this method have properties of random sequences, so it is widely used. The standard library functions for generating random numbers in C++ and Pascal also use this method.
Dongdong knows that the sequence produced this way has good randomness, but he is impatient and wants to know as soon as possible. Since the random numbers he needs are between , he will take modulo to get the number he wants, i.e., . You only need to tell Dongdong the value of .
Input Format
One line contains 6 space-separated integers and , where are non-negative integers, and are positive integers.
Output Format
Output a single number, which is .
11 8 7 1 5 3
2
Hint
We compute , thus .
Constraints: For of the testdata, , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号