QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#720434 | #5817. 小学生数学题 | KiharaTouma# | 100 ✓ | 530ms | 245576kb | C++14 | 889b | 2024-11-07 12:45:17 | 2024-11-07 12:45:18 |
Judging History
answer
//qoj5817
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll P = 998244353;
const int N = 2e7 + 10;
int n, k, fac[N];
int p[N], vis[N], pc, val[N];
ll qp(ll x, ll y){
ll ans = 1;
while(y){
if(y & 1){
ans = ans * x % P;
}
x = x * x % P;
y >>= 1;
}
return ans;
}
int main(){
scanf("%d%d", &n, &k);
fac[0] = 1;
for(int i = 1; i <= n; ++ i){
fac[i] = (ll)fac[i-1] * i % P;
}
val[1] = 1;
for(int i = 2; i <= n; ++ i){
if(!vis[i]){
p[++pc] = i;
val[i] = qp(i, k);
val[i] = qp(val[i], P-2);
}
for(int j = 1; j <= pc && i * p[j] <= n; ++ j){
vis[i*p[j]] = 1;
val[i*p[j]] = (ll)val[i] * val[p[j]] % P;
if(i % p[j] == 0){
break;
}
}
}
ll ans = 0;
for(int i = 1; i <= n; ++ i){
ans = (ans + 1ll * fac[i] * val[i]) % P;
}
printf("%lld\n", ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 204ms
memory: 123416kb
input:
9450395 1
output:
688545438
result:
ok single line: '688545438'
Test #2:
score: 10
Accepted
time: 194ms
memory: 117716kb
input:
8978812 1
output:
334565356
result:
ok single line: '334565356'
Test #3:
score: 10
Accepted
time: 187ms
memory: 116248kb
input:
8944235 1
output:
982802915
result:
ok single line: '982802915'
Test #4:
score: 10
Accepted
time: 152ms
memory: 94976kb
input:
7081118 3
output:
599009773
result:
ok single line: '599009773'
Test #5:
score: 10
Accepted
time: 161ms
memory: 104836kb
input:
7904241 3
output:
871243720
result:
ok single line: '871243720'
Test #6:
score: 10
Accepted
time: 218ms
memory: 128732kb
input:
9921275 3
output:
549818101
result:
ok single line: '549818101'
Test #7:
score: 10
Accepted
time: 480ms
memory: 220504kb
input:
17575748 14135489
output:
69236780
result:
ok single line: '69236780'
Test #8:
score: 10
Accepted
time: 530ms
memory: 245576kb
input:
19858362 14822524
output:
239890381
result:
ok single line: '239890381'
Test #9:
score: 10
Accepted
time: 521ms
memory: 233716kb
input:
18848696 15530895
output:
88125041
result:
ok single line: '88125041'
Test #10:
score: 10
Accepted
time: 489ms
memory: 223008kb
input:
17787945 13890407
output:
989967864
result:
ok single line: '989967864'
Extra Test:
score: 0
Extra Test Passed