QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#102369 | #5817. 小学生数学题 | zhyz | 100 ✓ | 540ms | 163748kb | C++14 | 1.0kb | 2023-05-03 10:41:42 | 2023-05-03 10:41:43 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int maxn = 2e7+10, mod = 998244353;
int prime[maxn],minp[maxn],pcnt;
int pw[maxn];
LL ksm(LL a,LL k)
{
LL ans = 1;
while(k)
{
if(k&1) ans = ans * a % mod;
k >>= 1;
a = a * a % mod;
}
return ans;
}
void init(int n,int k)
{
for(int i=2;i<=n;i++) minp[i] = i;
for(int i=2;i<=n;i++)
{
if(minp[i]==i) prime[pcnt++] = i;
for(int j=0,t;j<pcnt && (t=i*prime[j])<=n;j++)
{
minp[t] = prime[j];
if(i%prime[j]==0) break;
}
}
pw[1] = 1%mod;
for(int i=2;i<=n;i++)
{
if(minp[i]==i) pw[i] = ksm(i,k);
else pw[i] = 1LL*pw[minp[i]]*pw[i/minp[i]]%mod;
}
}
int main()
{
int n,k;
cin>>n>>k;
init(n,mod-1-k);
LL ans = 0,jc = 1;
for(int i=1;i<=n;i++)
{
jc = jc*i%mod;
(ans += jc*pw[i]) %= mod;
}
cout<<ans;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 10
Accepted
time: 257ms
memory: 81160kb
input:
9450395 1
output:
688545438
result:
ok single line: '688545438'
Test #2:
score: 10
Accepted
time: 246ms
memory: 77828kb
input:
8978812 1
output:
334565356
result:
ok single line: '334565356'
Test #3:
score: 10
Accepted
time: 230ms
memory: 76932kb
input:
8944235 1
output:
982802915
result:
ok single line: '982802915'
Test #4:
score: 10
Accepted
time: 175ms
memory: 63760kb
input:
7081118 3
output:
599009773
result:
ok single line: '599009773'
Test #5:
score: 10
Accepted
time: 196ms
memory: 69100kb
input:
7904241 3
output:
871243720
result:
ok single line: '871243720'
Test #6:
score: 10
Accepted
time: 254ms
memory: 84808kb
input:
9921275 3
output:
549818101
result:
ok single line: '549818101'
Test #7:
score: 10
Accepted
time: 461ms
memory: 146556kb
input:
17575748 14135489
output:
69236780
result:
ok single line: '69236780'
Test #8:
score: 10
Accepted
time: 540ms
memory: 163748kb
input:
19858362 14822524
output:
239890381
result:
ok single line: '239890381'
Test #9:
score: 10
Accepted
time: 478ms
memory: 155732kb
input:
18848696 15530895
output:
88125041
result:
ok single line: '88125041'
Test #10:
score: 10
Accepted
time: 450ms
memory: 147712kb
input:
17787945 13890407
output:
989967864
result:
ok single line: '989967864'
Extra Test:
score: 0
Extra Test Passed