#bzoj2875. 随机数生成器
随机数生成器
Title Description
Dong Dong has recently become obsessed with random algorithms, and random numbers are the basis for generating random algorithms. Dong Dong is preparing to use Linear Congruent Me thod to generate a random sequence. This method requires setting four non negative integer parameters , and generating a series of random numbers , where represents the remainder of the previous number divided by m. From this equation, it can be seen that the next number in this sequence is always generated by the previous number. The sequence generated by this method has the property of a random sequence, so this method is widely used, including the commonly used C++and Pascal library functions for generating random numbers, which also use this method. Dong Dong knows that the sequence generated in this way has good randomness, but he still wants to know as soon as possible what is. Since the random number required by the building is between , he needs to divide by and take the remainder to get the number he wants, which is . You just need to tell the building what the number he wants is .
Input format
integers separated by spaces , and , where are non negative integers and are positive integers
Output format
Output a number, which is .
Example
11 8 7 1 5 3
2
Example Description
Calculated as , therefore
Data scale and agreement
For all data: ,