QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#97520 | #5817. 小学生数学题 | sichengzhou | 60 | 638ms | 142192kb | C++14 | 791b | 2023-04-17 04:52:54 | 2023-04-17 04:52:55 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=2e7+7,mod=998244353;
int n,m;
int p[N],tp;
int pd[N];
LL val[N];
LL ksm(LL x,int y)
{
LL ret=1;
while(y)
{
if(y&1)
{
ret=ret*x%mod;
}
x=x*x%mod;
y>>=1;
}
return ret;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=2;i<=n;i++)
{
if(pd[i]==0)
{
p[++tp]=i;
}
for(int j=1;j<=tp&&(LL)p[j]*i<=n;j++)
{
pd[p[j]*i]=p[j];
if(i%p[j])
{
break;
}
}
}
LL cur=1,ans=0;
for(int i=1;i<=n;i++)
{
cur*=i;cur%=mod;
if(pd[i]==0)
{
val[i]=ksm(i,mod-1-m);
}else{
val[i]=val[i/pd[i]]*val[pd[i]]%mod;
}
// cout<<cur<<' '<<val[i]<<endl;
ans+=cur*val[i]%mod;
ans%=mod;
}
printf("%lld\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 10
Accepted
time: 629ms
memory: 133964kb
input:
9450395 1
output:
688545438
result:
ok single line: '688545438'
Test #2:
score: 10
Accepted
time: 622ms
memory: 127900kb
input:
8978812 1
output:
334565356
result:
ok single line: '334565356'
Test #3:
score: 10
Accepted
time: 585ms
memory: 127376kb
input:
8944235 1
output:
982802915
result:
ok single line: '982802915'
Test #4:
score: 10
Accepted
time: 485ms
memory: 103592kb
input:
7081118 3
output:
599009773
result:
ok single line: '599009773'
Test #5:
score: 10
Accepted
time: 533ms
memory: 113120kb
input:
7904241 3
output:
871243720
result:
ok single line: '871243720'
Test #6:
score: 10
Accepted
time: 638ms
memory: 142192kb
input:
9921275 3
output:
549818101
result:
ok single line: '549818101'
Test #7:
score: 0
Time Limit Exceeded
input:
17575748 14135489
output:
result:
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: 0
Time Limit Exceeded
input:
17787945 13890407