QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#278323#3161. Another Coin Weighing Puzzleddl_VS_pigeon#AC ✓70ms11720kbC++20929b2023-12-07 14:50:522023-12-07 14:50:52

Judging History

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

  • [2023-12-07 14:50:52]
  • 评测
  • 测评结果:AC
  • 用时:70ms
  • 内存:11720kb
  • [2023-12-07 14:50:52]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int M = 998244353;

int qpw(int a, int b) {
	a %= M;
	if (b < 0) {
		(b %= M - 1) += M - 1;
	}
	int c = 1;
	for (; b; b >>= 1, a = 1ll * a * a % M) {
		if (b & 1) {
			c = 1ll * c * a % M;
		}
	}
	return c;
}

int main(void) {
	ios::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
	int n, k;
	cin >> n >> k;
	vector<int> vis(k + 1), mu(k + 1), pri;
	mu[1] = 1;
	for (int i = 2; i <= k; i++) {
		if (!vis[i]) {
			pri.emplace_back(i);
			mu[i] = -1;
		}
		for (auto p : pri) {
			if (1ll * i * p > k) {
				break;
			}
			vis[i * p] = true;
			if (i % p == 0) {
				break;
			}
			mu[i * p] = -mu[i];
		}
	}
	int ans = 1;
	for (int i = 1; i <= k; i++) {
		ans = (ans + 1ll * mu[i] * (qpw(k / i * 2 + 1, n) - 1)) % M;
	}
	cout << (ans % M + M) % M << '\n';
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3500kb

input:

2 1

output:

9

result:

ok single line: '9'

Test #2:

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

input:

2 2

output:

17

result:

ok single line: '17'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3644kb

input:

10000 10000

output:

689223145

result:

ok single line: '689223145'

Test #4:

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

input:

9999 31

output:

986106162

result:

ok single line: '986106162'

Test #5:

score: 0
Accepted
time: 1ms
memory: 3640kb

input:

57 9817

output:

447253096

result:

ok single line: '447253096'

Test #6:

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

input:

501 499

output:

247755220

result:

ok single line: '247755220'

Test #7:

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

input:

97424 174829

output:

964884269

result:

ok single line: '964884269'

Test #8:

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

input:

11 13

output:

729153057

result:

ok single line: '729153057'

Test #9:

score: 0
Accepted
time: 13ms
memory: 5012kb

input:

200000 200000

output:

803771125

result:

ok single line: '803771125'

Test #10:

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

input:

199999 562

output:

865836540

result:

ok single line: '865836540'

Test #11:

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

input:

3539 189423

output:

530738158

result:

ok single line: '530738158'

Test #12:

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

input:

198324 173852

output:

963717515

result:

ok single line: '963717515'

Test #13:

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

input:

1 1

output:

3

result:

ok single line: '3'

Test #14:

score: 0
Accepted
time: 70ms
memory: 11548kb

input:

1000000 1000000

output:

800590912

result:

ok single line: '800590912'

Test #15:

score: 0
Accepted
time: 49ms
memory: 11720kb

input:

5034 999999

output:

946555033

result:

ok single line: '946555033'

Test #16:

score: 0
Accepted
time: 1ms
memory: 3636kb

input:

999998 2042

output:

713878368

result:

ok single line: '713878368'