QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#206891 | #5817. 小学生数学题 | Terryjoy | 100 ✓ | 485ms | 108372kb | C++14 | 1023b | 2023-10-07 23:51:04 | 2023-10-07 23:51:05 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 2e7 + 5;
const int mod = 998244353;
int pr[maxn + 5], inv[maxn + 5], cnt;
bool v[maxn + 5];
int mypow(int a, int b) {
int ans = 1;
while (b) {
if (b & 1)
ans = (ll) ans * a % mod;
a = (ll) a * a % mod;
b >>= 1;
}
return ans;
}
int n, k;
void init() {
for (int i = 2; i < maxn; ++i) {
if (!v[i]) {
pr[++cnt] = i;
inv[i] = mypow(mypow(i, k), mod - 2);
}
for (int j = 1; j <= cnt && pr[j] * i < maxn; ++j) {
v[i * pr[j]] = 1;
inv[i * pr[j]] = (ll) inv[i] * inv[pr[j]] % mod;
if (i % pr[j] == 0)
break;
}
}
}
int main() {
cin >> n >> k;
init();
ll ans = 1, sum = 1;
for (int i = 2; i <= n; ++i) {
sum = sum * i % mod;
ans = (ans + sum * inv[i] % mod) % mod;
}
cout << ans;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 10
Accepted
time: 311ms
memory: 107596kb
input:
9450395 1
output:
688545438
result:
ok single line: '688545438'
Test #2:
score: 10
Accepted
time: 308ms
memory: 107036kb
input:
8978812 1
output:
334565356
result:
ok single line: '334565356'
Test #3:
score: 10
Accepted
time: 311ms
memory: 106456kb
input:
8944235 1
output:
982802915
result:
ok single line: '982802915'
Test #4:
score: 10
Accepted
time: 304ms
memory: 106252kb
input:
7081118 3
output:
599009773
result:
ok single line: '599009773'
Test #5:
score: 10
Accepted
time: 308ms
memory: 107924kb
input:
7904241 3
output:
871243720
result:
ok single line: '871243720'
Test #6:
score: 10
Accepted
time: 326ms
memory: 107496kb
input:
9921275 3
output:
549818101
result:
ok single line: '549818101'
Test #7:
score: 10
Accepted
time: 477ms
memory: 108372kb
input:
17575748 14135489
output:
69236780
result:
ok single line: '69236780'
Test #8:
score: 10
Accepted
time: 483ms
memory: 107296kb
input:
19858362 14822524
output:
239890381
result:
ok single line: '239890381'
Test #9:
score: 10
Accepted
time: 485ms
memory: 106428kb
input:
18848696 15530895
output:
88125041
result:
ok single line: '88125041'
Test #10:
score: 10
Accepted
time: 479ms
memory: 107636kb
input:
17787945 13890407
output:
989967864
result:
ok single line: '989967864'
Extra Test:
score: 0
Extra Test Passed