QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#806656 | #8033. Fast Mod | PhoenixRebirth | AC ✓ | 452ms | 3844kb | C++23 | 752b | 2024-12-09 13:36:18 | 2024-12-09 13:36:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
// https://www.cnblogs.com/kyeecccccc/p/16926104.html
#define LL long long
struct Mod
{
LL m, p;
void init(int pp) { m = ((__int128)1 << 64) / pp; p = pp; }
LL operator ()(LL x)
{
return x - ((__int128(x) * m) >> 64) * p;
}
} mod;
int main() {
int x0, y0, x1, y1, alpha, beta, n, M;
cin >> alpha >> beta >> x0 >> y0 >> x1 >> y1 >> n >> M;
mod.init(M);
LL ans = 0;
for (int i = 2; i <= n; i++) {
int x2 = mod(1ll * alpha * x1 + 1ll * x0 * y1);
int y2 = mod(1ll * beta * y1 + 1ll * y0 * x1);
x0 = x1, y0 = y1;
x1 = x2, y1 = y2;
ans += x2;
}
cout << ans % M << '\n';
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3776kb
input:
114 514 1919 810 2024 112 154 12345678
output:
10095098
result:
ok answer is '10095098'
Test #2:
score: 0
Accepted
time: 46ms
memory: 3556kb
input:
299441828 557975370 185825413 389867512 789055585 702427833 10000000 998244353
output:
213479368
result:
ok answer is '213479368'
Test #3:
score: 0
Accepted
time: 136ms
memory: 3588kb
input:
201640599 316730877 236731096 870547384 321803723 818638005 30000000 998244353
output:
184315876
result:
ok answer is '184315876'
Test #4:
score: 0
Accepted
time: 452ms
memory: 3556kb
input:
454295813 797560957 820671325 549131050 200870107 596997226 100000000 998244353
output:
571671285
result:
ok answer is '571671285'
Test #5:
score: 0
Accepted
time: 451ms
memory: 3564kb
input:
568746783 797268245 962129329 543463404 966124052 703429023 100000000 999999999
output:
890564628
result:
ok answer is '890564628'
Test #6:
score: 0
Accepted
time: 452ms
memory: 3844kb
input:
134942359 726105292 765855056 658375599 203861321 577278130 100000000 1000000000
output:
837667109
result:
ok answer is '837667109'
Test #7:
score: 0
Accepted
time: 452ms
memory: 3552kb
input:
241497218 519623971 533438442 343085870 157943693 105603836 100000000 999999996
output:
122500520
result:
ok answer is '122500520'
Extra Test:
score: 0
Extra Test Passed