QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#288113#5817. 小学生数学题13431346214100 ✓469ms188640kbC++14730b2023-12-21 22:21:082023-12-21 22:21:08

Judging History

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

  • [2023-12-21 22:21:08]
  • 评测
  • 测评结果:100
  • 用时:469ms
  • 内存:188640kb
  • [2023-12-21 22:21:08]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define maxn 20000005
#define inf 1e18
#define mod 998244353
using namespace std;
ll n,m,ans1=1,inv[maxn],zs[maxn],cnt,ans;
bool bj[maxn];
ll ksm(ll x,ll y)
{
	ll ans=1;
	while(y)
	{
		if(y%2==1)ans=(ans*x)%mod;
		x=(x*x)%mod;
		y/=2;
	}
	return ans;
}
int main()
{
	cin>>n>>m;
	inv[1]=1;
	for(int i=2;i<=n;i++)
	{
		if(!bj[i])
		{
			bj[i]=true;
			inv[i]=ksm(ksm(i,m),mod-2);
			zs[++cnt]=i;
		}
		for(int j=1;j<=cnt&&zs[j]*i<=n;j++)
		{
			bj[zs[j]*i]=true;
			inv[zs[j]*i]=(inv[zs[j]]*inv[i])%mod;
			if(i%zs[j]==0)break;
		}
	}
	for(int i=1;i<=n;i++)
	{
		ans1=(ans1*i)%mod;
		ans=(ans+ans1*inv[i]%mod)%mod;
	}
	cout<<ans;
	return 0;
}

詳細信息

Test #1:

score: 10
Accepted
time: 174ms
memory: 94320kb

input:

9450395 1

output:

688545438

result:

ok single line: '688545438'

Test #2:

score: 10
Accepted
time: 167ms
memory: 91928kb

input:

8978812 1

output:

334565356

result:

ok single line: '334565356'

Test #3:

score: 10
Accepted
time: 162ms
memory: 91068kb

input:

8944235 1

output:

982802915

result:

ok single line: '982802915'

Test #4:

score: 10
Accepted
time: 135ms
memory: 71788kb

input:

7081118 3

output:

599009773

result:

ok single line: '599009773'

Test #5:

score: 10
Accepted
time: 149ms
memory: 80960kb

input:

7904241 3

output:

871243720

result:

ok single line: '871243720'

Test #6:

score: 10
Accepted
time: 183ms
memory: 100572kb

input:

9921275 3

output:

549818101

result:

ok single line: '549818101'

Test #7:

score: 10
Accepted
time: 442ms
memory: 167940kb

input:

17575748 14135489

output:

69236780

result:

ok single line: '69236780'

Test #8:

score: 10
Accepted
time: 469ms
memory: 188640kb

input:

19858362 14822524

output:

239890381

result:

ok single line: '239890381'

Test #9:

score: 10
Accepted
time: 461ms
memory: 179092kb

input:

18848696 15530895

output:

88125041

result:

ok single line: '88125041'

Test #10:

score: 10
Accepted
time: 428ms
memory: 169316kb

input:

17787945 13890407

output:

989967864

result:

ok single line: '989967864'

Extra Test:

score: 0
Extra Test Passed