QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#289347#5817. 小学生数学题Nwayy50 946ms79160kbC++14623b2023-12-23 17:10:042023-12-23 17:10:04

Judging History

你现在查看的是最新测评结果

  • [2023-12-23 17:10:04]
  • 评测
  • 测评结果:50
  • 用时:946ms
  • 内存:79160kb
  • [2023-12-23 17:10:04]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define N 20000005
#define int long long
const int mod=998244353;
int n,m,i,j,ans,k,f[N];
int qpow(int a,int b){
	int res=1;
	while(b){
		if(b&1) res=res*a%mod;
		b>>=1,a=a*a%mod;
	}
	return res;
}
int Mod(int x){
	return x-(x/mod*mod);
}
signed main(){
	scanf("%lld%lld",&n,&k);
	f[0]=1;for(i=1;i<=n;i++) f[i]=f[i-1]*i%mod;
	if(k==1){
		for(i=1;i<=n;i++) ans+=f[i-1],ans%=mod;
		printf("%lld\n",ans);
		return 0;
	}
	for(i=1;i<=n;i++){
		int p=qpow(i,k);
		p=qpow(p,mod-2);
		ans+=Mod(f[i]*p),ans=Mod(ans);
	}
	printf("%lld\n",ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 10
Accepted
time: 59ms
memory: 79160kb

input:

9450395 1

output:

688545438

result:

ok single line: '688545438'

Test #2:

score: 10
Accepted
time: 70ms
memory: 74456kb

input:

8978812 1

output:

334565356

result:

ok single line: '334565356'

Test #3:

score: 10
Accepted
time: 70ms
memory: 75696kb

input:

8944235 1

output:

982802915

result:

ok single line: '982802915'

Test #4:

score: 10
Accepted
time: 845ms
memory: 59932kb

input:

7081118 3

output:

599009773

result:

ok single line: '599009773'

Test #5:

score: 10
Accepted
time: 946ms
memory: 67368kb

input:

7904241 3

output:

871243720

result:

ok single line: '871243720'

Test #6:

score: 0
Time Limit Exceeded

input:

9921275 3

output:


result:


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

output:


result: