QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#439483 | #6195. Linear Congruential Generator Problem | linak | RE | 0ms | 0kb | C++17 | 1.8kb | 2024-06-12 01:13:40 | 2024-06-12 01:13:40 |
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
int tc;
cin >> tc;
for (int tk = 1; tk <= tc; tk++) {
cout << "Case #" << tk << ": ";
ll m, a, c, x, l1, r1, l2, r2;
cin >> m >> a >> c >> x >> l1 >> r1 >> l2 >> r2;
set<ll> cycle;
vector<ll> k;
ll u = x;
while (!cycle.count(u)) {
cycle.insert(u);
k.push_back(u);
u = (a * u + c) % m;
}
ll ka[m], kb[m];
memset(ka, 0, sizeof(ka));
memset(kb, 0, sizeof(kb));
ll g = (r1 - l1 + 1) / m;
for (ll u : k) ka[u] += g;
for (int i = 0; i < (r1 - l1 + 1) % m; i++) ka[k[(l1 + i) % k.size()]]++;
g = (r2 - l2 + 1) / m;
for (ll u : k) kb[u] += g;
for (int i = 0; i < (r2 - l2 + 1) % m; i++) kb[k[(l2 + i) % k.size()]]++;
ll imos[m + 1][2];
memset(imos, 0, sizeof(imos));
for (int i = 0; i < m; i++) {
int u;
for (int j = 1; j <= i; j = u + 1) {
u = i / (i / j);
imos[j][0] -= i / j * ka[i];
imos[j][1] += ka[i] * i;
imos[u + 1][0] += i / j * ka[i];
imos[u + 1][1] -= ka[i] * i;
}
imos[i + 1][1] += ka[i] * i;
}
ll ans = 0;
for (int i = 1; i <= m; i++) {
imos[i][0] += imos[i - 1][0];
imos[i][1] += imos[i - 1][1];
ans += kb[i - 1] * (imos[i][0] * i + imos[i][1]);
}
cout << ans << "\n";
}
}
詳細信息
Test #1:
score: 0
Runtime Error
input:
100000 38898 35776 38192 80605 84959 84530 62023 71929 48220 44197 86087 74579 85822 73930 56932 8586 14771 97888 19725 83418 68537 51209 79063 941 18772 55012 95724 21509 54841 4758 53698 1878 15489 65235 63470 28437 47179 2603 9808 54485 34353 93975 75059 77384 24776 71739 15230 90871 29323 92012 ...