QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#76945 | #3161. Another Coin Weighing Puzzle | WTR2007 | AC ✓ | 103ms | 11924kb | C++20 | 1.2kb | 2023-02-12 18:36:58 | 2023-02-12 18:37:00 |
Judging History
answer
#include<bits/stdc++.h>
#define MULT_TEST 0
#define int long long
using namespace std;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const int MOD = 998244353;
inline int read() {
int w = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if(ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
w = (w << 1) + (w << 3) + ch - 48;
ch = getchar();
}
return w * f;
}
inline int Pow(int a, int b){
int ans = 1;
for(; b; b >>= 1){
if(b & 1) ans = ans * a % MOD;
a = a * a % MOD;
}
return ans;
}
inline void Solve() {
int m, k, ans = 1;
m = read(); k = read();
vector<int> prime, mu(k + 1);
vector<bool> vis(k + 1);
mu[1] = 1;
for (int i = 2; i <= k; i++) {
if (!vis[i]) {
prime.push_back(i);
mu[i] = -1;
}
for (auto p : prime) {
if (i * p > k) break;
vis[i * p] = 1;
if (i % p == 0) break;
mu[p * i] = -mu[i];
}
}
for (int i = 1; i <= k; i++) {
ans += mu[i] * (Pow(2 * (k / i) % MOD + 1, m) - 1 + MOD) % MOD;
ans = (ans % MOD + MOD) % MOD;
}
printf("%lld\n", ans);
}
signed main() {
int T = 1;
#if MULT_TEST
T = read();
#endif
while (T--) Solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3472kb
input:
2 1
output:
9
result:
ok single line: '9'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3464kb
input:
2 2
output:
17
result:
ok single line: '17'
Test #3:
score: 0
Accepted
time: 3ms
memory: 3704kb
input:
10000 10000
output:
689223145
result:
ok single line: '689223145'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3560kb
input:
9999 31
output:
986106162
result:
ok single line: '986106162'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3724kb
input:
57 9817
output:
447253096
result:
ok single line: '447253096'
Test #6:
score: 0
Accepted
time: 3ms
memory: 3492kb
input:
501 499
output:
247755220
result:
ok single line: '247755220'
Test #7:
score: 0
Accepted
time: 18ms
memory: 4628kb
input:
97424 174829
output:
964884269
result:
ok single line: '964884269'
Test #8:
score: 0
Accepted
time: 2ms
memory: 3552kb
input:
11 13
output:
729153057
result:
ok single line: '729153057'
Test #9:
score: 0
Accepted
time: 21ms
memory: 4884kb
input:
200000 200000
output:
803771125
result:
ok single line: '803771125'
Test #10:
score: 0
Accepted
time: 2ms
memory: 3556kb
input:
199999 562
output:
865836540
result:
ok single line: '865836540'
Test #11:
score: 0
Accepted
time: 16ms
memory: 4840kb
input:
3539 189423
output:
530738158
result:
ok single line: '530738158'
Test #12:
score: 0
Accepted
time: 19ms
memory: 4608kb
input:
198324 173852
output:
963717515
result:
ok single line: '963717515'
Test #13:
score: 0
Accepted
time: 2ms
memory: 3600kb
input:
1 1
output:
3
result:
ok single line: '3'
Test #14:
score: 0
Accepted
time: 103ms
memory: 11924kb
input:
1000000 1000000
output:
800590912
result:
ok single line: '800590912'
Test #15:
score: 0
Accepted
time: 76ms
memory: 11828kb
input:
5034 999999
output:
946555033
result:
ok single line: '946555033'
Test #16:
score: 0
Accepted
time: 1ms
memory: 3512kb
input:
999998 2042
output:
713878368
result:
ok single line: '713878368'