Pro.ID10096 TitleRandom Gap Title链接http://10.20.2.8/oj/exercise/problem?problem_id=10096 AC0 Submit0 Ratio- 时间&空间限制描述The pseudo-random number genegators (or RNGs for short) are widely used in statistical calculations. One of the simplest and ubiquitious is the linear congruence RNG, that calculates the n-th random number Rn as Rn = (a*Rn-1 + c) mod m, where a, c and m are constants. For example, the sequence for a = 15, c = 7, m = 100 and starting value R0 = 1 is 1, 22, 37, 62, 37, 62, ... Linear RNG is very fast, and can yield surprisinly good sequence of random numbers, given the right choice of constants. There are various measures of RNG quality, and your task is to calculate one of them, namely the longest gap between members of the sequence. More precisely, given the values of a, c, m, and R0, find such two elements Ri < Rj that:
输入Input contains integer numbers a c m R0. 0 ≤ a, c, R0 ≤ 107, 1 ≤ m ≤ 16000000, a*m + c < 232. 输出Description The pseudo-random number genegators (or RNGs for short) are widely used in statistical calculations. One of the simplest and ubiquitious is the linear congruence RNG, that calculates the n-th random number Rn as Rn = (a*Rn-1 + c) mod m, where a, c and m are constants. For example, the sequence for a = 15, c = 7, m = 100 and starting value R0 = 1 is 1, 22, 37, 62, 37, 62, ... Linear RNG is very fast, and can yield surprisinly good sequence of random numbers, given the right choice of constants. There are various measures of RNG quality, and your task is to calculate one of them, namely the longest gap between members of the sequence. More precisely, given the values of a, c, m, and R0, find such two elements Ri < Rj that:
Input Input contains integer numbers a c m R0. 0 ≤ a, c, R0 ≤ 107, 1 ≤ m ≤ 16000000, a*m + c < 232. Output Output should contain the single number --- the maximal difference found. Sample Input 15 7 100 1 Sample Output 25 Source 样例输入15 7 100 1 样例输出25 作者 |