QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#56575#3161. Another Coin Weighing PuzzletricyzhkxAC ✓30ms23100kbC++14805b2022-10-20 08:17:002022-10-20 08:17:02

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.
  • [2022-10-20 08:17:02]
  • Judged
  • Verdict: AC
  • Time: 30ms
  • Memory: 23100kb
  • [2022-10-20 08:17:00]
  • Submitted

answer

# include <bits/stdc++.h>
using namespace std;
const int mod=998244353;
typedef long long ll;
int prime[2000010],mu[2000010],pw[2000010],tot;
bool ispri[2000010];
ll power(ll a,int b)
{
	ll ans=1;
	for(;b;b>>=1,a=a*a%mod)
		if(b&1) ans=ans*a%mod;
	return ans;
}
int main()
{
	int m,k,ans=1;
	cin>>m>>k;
	memset(ispri,true,sizeof(ispri));
	ispri[0]=ispri[1]=0;mu[1]=pw[1]=1;
	for(int i=2;i<=2*k+1;i++)
	{
		if(ispri[i]) prime[++tot]=i,mu[i]=-1,pw[i]=power(i,m);
		for(int j=1;j<=tot && i*prime[j]<=2*k+1;j++)
		{
			ispri[i*prime[j]]=0;
			pw[i*prime[j]]=(ll)pw[i]*pw[prime[j]]%mod;
			if(i%prime[j]) mu[i*prime[j]]=-mu[i];
			else break;
		}
	}
	for(int i=1;i<=k;i++)
		if(mu[i]) ans=(ans+(mu[i]>0?pw[2*(k/i)+1]-1:mod-pw[2*(k/i)+1]+1))%mod;
	cout<<ans<<endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 9928kb

input:

2 1

output:

9

result:

ok single line: '9'

Test #2:

score: 0
Accepted
time: 3ms
memory: 10724kb

input:

2 2

output:

17

result:

ok single line: '17'

Test #3:

score: 0
Accepted
time: 4ms
memory: 10244kb

input:

10000 10000

output:

689223145

result:

ok single line: '689223145'

Test #4:

score: 0
Accepted
time: 0ms
memory: 9876kb

input:

9999 31

output:

986106162

result:

ok single line: '986106162'

Test #5:

score: 0
Accepted
time: 2ms
memory: 10896kb

input:

57 9817

output:

447253096

result:

ok single line: '447253096'

Test #6:

score: 0
Accepted
time: 2ms
memory: 11208kb

input:

501 499

output:

247755220

result:

ok single line: '247755220'

Test #7:

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

input:

97424 174829

output:

964884269

result:

ok single line: '964884269'

Test #8:

score: 0
Accepted
time: 4ms
memory: 9728kb

input:

11 13

output:

729153057

result:

ok single line: '729153057'

Test #9:

score: 0
Accepted
time: 9ms
memory: 14496kb

input:

200000 200000

output:

803771125

result:

ok single line: '803771125'

Test #10:

score: 0
Accepted
time: 0ms
memory: 10704kb

input:

199999 562

output:

865836540

result:

ok single line: '865836540'

Test #11:

score: 0
Accepted
time: 9ms
memory: 13844kb

input:

3539 189423

output:

530738158

result:

ok single line: '530738158'

Test #12:

score: 0
Accepted
time: 4ms
memory: 14500kb

input:

198324 173852

output:

963717515

result:

ok single line: '963717515'

Test #13:

score: 0
Accepted
time: 2ms
memory: 11112kb

input:

1 1

output:

3

result:

ok single line: '3'

Test #14:

score: 0
Accepted
time: 30ms
memory: 23100kb

input:

1000000 1000000

output:

800590912

result:

ok single line: '800590912'

Test #15:

score: 0
Accepted
time: 25ms
memory: 21676kb

input:

5034 999999

output:

946555033

result:

ok single line: '946555033'

Test #16:

score: 0
Accepted
time: 2ms
memory: 11396kb

input:

999998 2042

output:

713878368

result:

ok single line: '713878368'