QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#234552#3161. Another Coin Weighing PuzzlePhantomThreshold#AC ✓63ms14392kbC++201.1kb2023-11-01 19:11:002023-11-01 19:11:00

Judging History

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

  • [2023-11-01 19:11:00]
  • 评测
  • 测评结果:AC
  • 用时:63ms
  • 内存:14392kb
  • [2023-11-01 19:11:00]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll mod=998244353;
ll ksm(ll a,ll x){
	ll ret=1;
	for (;x;x>>=1,a=a*a%mod) if (x&1) ret=ret*a%mod;
	return ret;	
}
ll inv(ll a){return ksm(a,mod-2);}

const int maxn=1000000;
bool notp[maxn+50];
int pcnt=0;
ll p[(maxn>>2)+50];
ll mu[maxn+50];

void prepare(){
	notp[1]=1;
	mu[1]=1;
	for (int i=2;i<=maxn;i++){
		if (!notp[i]){
			p[++pcnt]=i;
			mu[i]=mod-1;
		}
		for (int j=1,x=1;j<=pcnt && (x=i*p[j])<=maxn;j++){
			notp[x]=1;
			if (i%p[j]){
				mu[x]=mod-mu[i];
			}
			else{
				mu[x]=0;
				break;	
			}
		}
	}
//	for (int i=1;i<=maxn;i++) assert(0<=mu[i] && mu[i]<=mod);
}

int main(){
	ios_base::sync_with_stdio(false);
	prepare();
	/*
	for (int i=1;i<=20;i++) cerr << p[i] << " ";
	cerr << endl;
	for (int i=1;i<=20;i++) cerr << mu[i] << " ";
	cerr << endl;
	*/
	ll m,k;
	cin >> m >> k;
	
	ll ans=1;
	for (ll i=1;i<=k;i++){
		ans=(ans+mu[i]*(ksm(k/i*2+1,m)+mod-1))%mod;
	}
//	ans=(ans+mod-1)*ksm(2,m)%mod;
//	ans=(ans+ksm(3,m))%mod;
	cout << ans << "\n";
	return 0;	
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 14392kb

input:

2 1

output:

9

result:

ok single line: '9'

Test #2:

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

input:

2 2

output:

17

result:

ok single line: '17'

Test #3:

score: 0
Accepted
time: 6ms
memory: 13100kb

input:

10000 10000

output:

689223145

result:

ok single line: '689223145'

Test #4:

score: 0
Accepted
time: 6ms
memory: 13508kb

input:

9999 31

output:

986106162

result:

ok single line: '986106162'

Test #5:

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

input:

57 9817

output:

447253096

result:

ok single line: '447253096'

Test #6:

score: 0
Accepted
time: 6ms
memory: 13564kb

input:

501 499

output:

247755220

result:

ok single line: '247755220'

Test #7:

score: 0
Accepted
time: 15ms
memory: 13080kb

input:

97424 174829

output:

964884269

result:

ok single line: '964884269'

Test #8:

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

input:

11 13

output:

729153057

result:

ok single line: '729153057'

Test #9:

score: 0
Accepted
time: 16ms
memory: 13068kb

input:

200000 200000

output:

803771125

result:

ok single line: '803771125'

Test #10:

score: 0
Accepted
time: 6ms
memory: 13296kb

input:

199999 562

output:

865836540

result:

ok single line: '865836540'

Test #11:

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

input:

3539 189423

output:

530738158

result:

ok single line: '530738158'

Test #12:

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

input:

198324 173852

output:

963717515

result:

ok single line: '963717515'

Test #13:

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

input:

1 1

output:

3

result:

ok single line: '3'

Test #14:

score: 0
Accepted
time: 63ms
memory: 13788kb

input:

1000000 1000000

output:

800590912

result:

ok single line: '800590912'

Test #15:

score: 0
Accepted
time: 41ms
memory: 13016kb

input:

5034 999999

output:

946555033

result:

ok single line: '946555033'

Test #16:

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

input:

999998 2042

output:

713878368

result:

ok single line: '713878368'