QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#291479 | #5817. 小学生数学题 | Yuics | 100 ✓ | 527ms | 324788kb | C++14 | 862b | 2023-12-26 19:33:29 | 2023-12-26 19:33:30 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
constexpr int N = 2e7 + 7;
constexpr i64 mod = 998244353;
i64 n, k, cnt;
i64 inv[N], fac[N], pri[N];
i64 power(i64 a, i64 b) {
i64 res = 1 % mod;
for (; b; b >>= 1) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
}
return res;
}
int main() {
scanf("%lld %lld", &n, &k);
inv[1] = 1;
for (i64 i = 2; i <= n; i++) {
if (!pri[i]) {
pri[i] = i;
fac[++cnt] = i;
inv[i] = power(power(i, mod - 2), k);
}
for (i64 j = 1; fac[j] * i <= n && fac[j] < pri[i]; j++) {
pri[fac[j] * i] = fac[j];
inv[fac[j] * i] = inv[fac[j]] * inv[i] % mod;
}
}
i64 tot = 1, ans = 0;
for (i64 i = 1; i <= n; i++) {
ans = ((ans + tot * inv[i]) % mod) % mod;
tot = tot * (i + 1) % mod;
}
printf("%lld\n", ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 10
Accepted
time: 224ms
memory: 159540kb
input:
9450395 1
output:
688545438
result:
ok single line: '688545438'
Test #2:
score: 10
Accepted
time: 192ms
memory: 151564kb
input:
8978812 1
output:
334565356
result:
ok single line: '334565356'
Test #3:
score: 10
Accepted
time: 192ms
memory: 151444kb
input:
8944235 1
output:
982802915
result:
ok single line: '982802915'
Test #4:
score: 10
Accepted
time: 156ms
memory: 120920kb
input:
7081118 3
output:
599009773
result:
ok single line: '599009773'
Test #5:
score: 10
Accepted
time: 168ms
memory: 134492kb
input:
7904241 3
output:
871243720
result:
ok single line: '871243720'
Test #6:
score: 10
Accepted
time: 211ms
memory: 164888kb
input:
9921275 3
output:
549818101
result:
ok single line: '549818101'
Test #7:
score: 10
Accepted
time: 460ms
memory: 288540kb
input:
17575748 14135489
output:
69236780
result:
ok single line: '69236780'
Test #8:
score: 10
Accepted
time: 527ms
memory: 324788kb
input:
19858362 14822524
output:
239890381
result:
ok single line: '239890381'
Test #9:
score: 10
Accepted
time: 508ms
memory: 308716kb
input:
18848696 15530895
output:
88125041
result:
ok single line: '88125041'
Test #10:
score: 10
Accepted
time: 469ms
memory: 291928kb
input:
17787945 13890407
output:
989967864
result:
ok single line: '989967864'
Extra Test:
score: 0
Extra Test Passed