QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#376752 | #3161. Another Coin Weighing Puzzle | ckiseki# | AC ✓ | 85ms | 11624kb | C++20 | 1.7kb | 2024-04-04 16:15:41 | 2024-04-04 16:15:41 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define all(x) begin(x), end(x)
#ifdef CKISEKI
#define safe cerr << __PRETTY_FUNCTION__ << " line " << __LINE__ << "\n";
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
void debug_(auto s, auto ...a) {
cerr << "\e[1;32m(" << s << ") = (";
int f = 0;
(..., (cerr << (f++ ? ", " : "") << a));
cerr << ")\e[0m\n";
}
#include <experimental/iterator>
void orange_(auto s, auto L, auto R) {
cerr << "\e[1;33m[ " << s << " ] = [ ";
using namespace experimental;
copy(L, R, make_ostream_joiner(cerr, ", "));
cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) safe
#define orange(...) safe
#endif
const int mod = 998244353;
int add(int a, int b) {
return a + b >= mod ? a + b - mod : a + b;
}
int sub(int a, int b) {
return a - b < 0 ? a - b + mod : a - b;
}
int mul(int64_t a, int64_t b) {
return static_cast<int>(a * b % mod);
}
int modpow(int e, int p) {
int r = 1;
while (p) {
if (p & 1) r = mul(r, e);
e = mul(e, e);
p >>= 1;
}
return r;
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int m, k;
cin >> m >> k;
vector<int> mu(k + 1), sieve(k + 1), primes;
mu[1] = 1;
for (int i = 2; i <= k; i++) {
if (!sieve[i]) {
primes.push_back(i);
mu[i] = mod - 1;
}
for (int p : primes) {
if (i * p > k) break;
sieve[i * p] = true;
if (i % p == 0) {
mu[i * p] = 0;
break;
} else {
mu[i * p] = sub(0, mu[i]);
}
}
}
int ans = 1;
for (int i = 1; i <= k; i++) {
const int C = k / i * 2 + 1;
ans = add(ans, mul(mu[i], sub(modpow(C, m), 1)));
}
cout << ans << '\n';
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3528kb
input:
2 1
output:
9
result:
ok single line: '9'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
2 2
output:
17
result:
ok single line: '17'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3632kb
input:
10000 10000
output:
689223145
result:
ok single line: '689223145'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
9999 31
output:
986106162
result:
ok single line: '986106162'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3704kb
input:
57 9817
output:
447253096
result:
ok single line: '447253096'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
501 499
output:
247755220
result:
ok single line: '247755220'
Test #7:
score: 0
Accepted
time: 14ms
memory: 4816kb
input:
97424 174829
output:
964884269
result:
ok single line: '964884269'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
11 13
output:
729153057
result:
ok single line: '729153057'
Test #9:
score: 0
Accepted
time: 12ms
memory: 5080kb
input:
200000 200000
output:
803771125
result:
ok single line: '803771125'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
199999 562
output:
865836540
result:
ok single line: '865836540'
Test #11:
score: 0
Accepted
time: 11ms
memory: 4952kb
input:
3539 189423
output:
530738158
result:
ok single line: '530738158'
Test #12:
score: 0
Accepted
time: 14ms
memory: 4744kb
input:
198324 173852
output:
963717515
result:
ok single line: '963717515'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
1 1
output:
3
result:
ok single line: '3'
Test #14:
score: 0
Accepted
time: 85ms
memory: 11624kb
input:
1000000 1000000
output:
800590912
result:
ok single line: '800590912'
Test #15:
score: 0
Accepted
time: 50ms
memory: 11624kb
input:
5034 999999
output:
946555033
result:
ok single line: '946555033'
Test #16:
score: 0
Accepted
time: 1ms
memory: 3616kb
input:
999998 2042
output:
713878368
result:
ok single line: '713878368'