0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-30 16:56:27 +00:00
OI-codes/S2OJ/1803/1803.cpp

31 lines
518 B
C++

#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 3e7 + 5;
int n, s, b, c, d, a[N], ans;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> s >> b >> c >> d;
for (int i = 1; i <= n; i++) {
a[i] = i;
s = (static_cast<long long>(s) * b + c) % d;
std::swap(a[i], a[s % i + 1]);
}
for (int i = 1; i <= n; i++) {
ans = std::max(ans, i - a[i]);
}
cout << ans << endl;
return 0;
}