10096_RandomGap

2022-5-16 18:16| 发布者: Hocassian| 查看: 86| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-3-89504536885500-Problem List-采集的数据-后羿采集器.html

Pro.ID

10096

Title

Random Gap

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=10096

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 8000/4000 MS (Java/Others)     Memory Limit: 262144/262144 K (Java/Others)
  • 描述

    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:

    1. there are no other Rk that RiRkRj,

    2. the difference Rj - Ri is maximal.

    输入

    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:

    1. there are no other Rk that RiRkRj,

    2. the difference Rj - Ri is maximal.

    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

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部