QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#244493 | #5817. 小学生数学题 | FriskLSZ | 100 ✓ | 478ms | 186624kb | C++14 | 1.0kb | 2023-11-09 10:11:42 | 2023-11-09 10:11:43 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned ll
#define i128 __int128
#define db double
#define ld long db
#define M 20000005
#define N 200001
#define mod 998244353
#define mod2 1222827239
#define base 51787
#define base2 38833
#define inf 1e9+7
#define dinf 1e15
#define linf 7e18
#define eps 1e-15
#define delta 0.99777
ll qpow(ll a,ll b,ll p){
ll e=1;
while(b){
if(b&1) e=e*a%p;
a=a*a%p;
b>>=1;
}
return e;
}
int n,k;
int prime[M],cnt;
bool vis[M];
int inv[M];
int fac[M];
void init(){
inv[1]=1;
fac[0]=fac[1]=1;
for(int i=2;i<M;++i){
fac[i]=1ll*fac[i-1]*i%mod;
if(!vis[i]){
prime[++cnt]=i;
inv[i]=qpow(qpow(i,k,mod),mod-2,mod);
}
for(int j=1;j<=cnt&&i*prime[j]<M;++j){
vis[i*prime[j]]=1;
inv[i*prime[j]]=1ll*inv[i]*inv[prime[j]]%mod;
if(i%prime[j]==0) break;
}
}
}
int ans;
int main(){
scanf("%d %d",&n,&k);
init();
for(int i=1;i<=n;++i) ans=(ans+1ll*fac[i]*inv[i]%mod)%mod;
printf("%d\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 10
Accepted
time: 327ms
memory: 186624kb
input:
9450395 1
output:
688545438
result:
ok single line: '688545438'
Test #2:
score: 10
Accepted
time: 372ms
memory: 185352kb
input:
8978812 1
output:
334565356
result:
ok single line: '334565356'
Test #3:
score: 10
Accepted
time: 317ms
memory: 185316kb
input:
8944235 1
output:
982802915
result:
ok single line: '982802915'
Test #4:
score: 10
Accepted
time: 317ms
memory: 185296kb
input:
7081118 3
output:
599009773
result:
ok single line: '599009773'
Test #5:
score: 10
Accepted
time: 327ms
memory: 186248kb
input:
7904241 3
output:
871243720
result:
ok single line: '871243720'
Test #6:
score: 10
Accepted
time: 328ms
memory: 184760kb
input:
9921275 3
output:
549818101
result:
ok single line: '549818101'
Test #7:
score: 10
Accepted
time: 457ms
memory: 185900kb
input:
17575748 14135489
output:
69236780
result:
ok single line: '69236780'
Test #8:
score: 10
Accepted
time: 469ms
memory: 184728kb
input:
19858362 14822524
output:
239890381
result:
ok single line: '239890381'
Test #9:
score: 10
Accepted
time: 467ms
memory: 185996kb
input:
18848696 15530895
output:
88125041
result:
ok single line: '88125041'
Test #10:
score: 10
Accepted
time: 478ms
memory: 185880kb
input:
17787945 13890407
output:
989967864
result:
ok single line: '989967864'
Extra Test:
score: 0
Extra Test Passed