QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#89280 | #5817. 小学生数学题 | cyl001 | 80 | 990ms | 236748kb | C++14 | 800b | 2023-03-19 15:24:36 | 2023-03-19 15:24:38 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 2e7 + 5,p = 998244353;
int n,k,tot,sum,inv[N],fac[N],mi[N],pr[N];
bool f[N];
int ksm(int x,int y)
{
int ret = 1;
while(y)
{
if(y & 1) ret = 1LL * ret * x % p;
x = 1LL * x * x % p;
y >>= 1;
}
return ret;
}
int main()
{
scanf("%d%d",&n,&k);
inv[1] = fac[1] = mi[1] = sum = 1;
for(int i = 2;i <= n;i++)
{
inv[i] = p - 1LL * (p / i) * inv[p % i] % p;
fac[i] = 1LL * fac[i - 1] * i % p;
if(!f[i])
{
mi[i] = ksm(inv[i],k);
pr[++tot] = i;
}
sum = (sum + 1LL * fac[i] * mi[i] % p) % p;
for(int j = 1;j <= tot && pr[j] * i <= n;j++)
{
mi[i * pr[j]] = 1LL * mi[i] * mi[pr[j]] % p;
f[i * pr[j]] = 1;
if(i % pr[j] == 0) break;
}
}
printf("%d\n",sum);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 10
Accepted
time: 427ms
memory: 132548kb
input:
9450395 1
output:
688545438
result:
ok single line: '688545438'
Test #2:
score: 10
Accepted
time: 350ms
memory: 125664kb
input:
8978812 1
output:
334565356
result:
ok single line: '334565356'
Test #3:
score: 10
Accepted
time: 360ms
memory: 127668kb
input:
8944235 1
output:
982802915
result:
ok single line: '982802915'
Test #4:
score: 10
Accepted
time: 279ms
memory: 102028kb
input:
7081118 3
output:
599009773
result:
ok single line: '599009773'
Test #5:
score: 10
Accepted
time: 313ms
memory: 111652kb
input:
7904241 3
output:
871243720
result:
ok single line: '871243720'
Test #6:
score: 10
Accepted
time: 434ms
memory: 137876kb
input:
9921275 3
output:
549818101
result:
ok single line: '549818101'
Test #7:
score: 10
Accepted
time: 970ms
memory: 235804kb
input:
17575748 14135489
output:
69236780
result:
ok single line: '69236780'
Test #8:
score: 0
Time Limit Exceeded
input:
19858362 14822524
output:
result:
Test #9:
score: 0
Time Limit Exceeded
input:
18848696 15530895
output:
result:
Test #10:
score: 10
Accepted
time: 990ms
memory: 236748kb
input:
17787945 13890407
output:
989967864
result:
ok single line: '989967864'