QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#74273#3161. Another Coin Weighing PuzzleStarSilkAC ✓307ms8684kbC++14866b2023-01-31 12:47:422023-01-31 12:47:43

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-31 12:47:43]
  • Judged
  • Verdict: AC
  • Time: 307ms
  • Memory: 8684kb
  • [2023-01-31 12:47:42]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
long long mod=998244353;
long long qpow(long long a,long long b){
	long long ans=1;
	while(b>0)
	{
		if(b&1)ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans;
}
bool ntprime[1000001]={};
int prime[100000],pricnt=0,N=1000000,val[1000001]={};
void gen(){
	int i,j;
	ntprime[1]=1;
	val[1]=1;
	for(i=2;i<=N;i++)
	{
		if(!ntprime[i])
		{
			prime[pricnt]=i;
			val[i]=-1;
			pricnt++;
		}
		for(j=0;j<pricnt&&i*prime[j]<=N;j++)
		{
			ntprime[i*prime[j]]=1;
			if(i%prime[j]==0)break;
			else val[i*prime[j]]=val[i]*val[prime[j]];
		}
	}
}
int main(int argc, char** argv) {
	ios::sync_with_stdio(false),cin.tie(0);
	int m,k,i,j;
	long long ans=0;
	gen();
	cin>>m>>k;
	for(i=1;i<=k;i++)ans=(ans+val[i]*((qpow(k/i*2+1,m)+mod-1)%mod)+mod)%mod;
	cout<<(ans+1)%mod<<'\n';
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 8ms
memory: 8624kb

input:

2 1

output:

9

result:

ok single line: '9'

Test #2:

score: 0
Accepted
time: 10ms
memory: 8516kb

input:

2 2

output:

17

result:

ok single line: '17'

Test #3:

score: 0
Accepted
time: 7ms
memory: 8684kb

input:

10000 10000

output:

689223145

result:

ok single line: '689223145'

Test #4:

score: 0
Accepted
time: 12ms
memory: 8536kb

input:

9999 31

output:

986106162

result:

ok single line: '986106162'

Test #5:

score: 0
Accepted
time: 8ms
memory: 8564kb

input:

57 9817

output:

447253096

result:

ok single line: '447253096'

Test #6:

score: 0
Accepted
time: 7ms
memory: 8624kb

input:

501 499

output:

247755220

result:

ok single line: '247755220'

Test #7:

score: 0
Accepted
time: 52ms
memory: 8480kb

input:

97424 174829

output:

964884269

result:

ok single line: '964884269'

Test #8:

score: 0
Accepted
time: 12ms
memory: 8564kb

input:

11 13

output:

729153057

result:

ok single line: '729153057'

Test #9:

score: 0
Accepted
time: 62ms
memory: 8512kb

input:

200000 200000

output:

803771125

result:

ok single line: '803771125'

Test #10:

score: 0
Accepted
time: 7ms
memory: 8484kb

input:

199999 562

output:

865836540

result:

ok single line: '865836540'

Test #11:

score: 0
Accepted
time: 45ms
memory: 8540kb

input:

3539 189423

output:

530738158

result:

ok single line: '530738158'

Test #12:

score: 0
Accepted
time: 54ms
memory: 8532kb

input:

198324 173852

output:

963717515

result:

ok single line: '963717515'

Test #13:

score: 0
Accepted
time: 11ms
memory: 8540kb

input:

1 1

output:

3

result:

ok single line: '3'

Test #14:

score: 0
Accepted
time: 307ms
memory: 8492kb

input:

1000000 1000000

output:

800590912

result:

ok single line: '800590912'

Test #15:

score: 0
Accepted
time: 223ms
memory: 8532kb

input:

5034 999999

output:

946555033

result:

ok single line: '946555033'

Test #16:

score: 0
Accepted
time: 11ms
memory: 8568kb

input:

999998 2042

output:

713878368

result:

ok single line: '713878368'