Logo
(追記) (追記ここまで)

7848번 - Random Gap 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 128 MB157361917.431%

문제

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 = (aRn - 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 Ri &le; Rk &le; Rj,
  2. the difference Rj &minus; Ri is maximal.

입력

Input file contains integer numbers a c m R0.

출력

Output file should contain the single number -- the maximal difference found.

제한

  • 0 ≤ a, c, R0 ≤ 107,
  • 1 ≤ m ≤ 16000000,
  • am + c < 232.

예제 입력 1

15 7 100 1

예제 출력 1

25

예제 입력 2

2 0 127 5

예제 출력 2

26

힌트

출처

ICPC > Regionals > Northern Eurasia > Far Eastern Russia Regional Contest > NEERC Far-Eastern Subregional 2004 C번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /