QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#283896 | #3161. Another Coin Weighing Puzzle | warner1129 | AC ✓ | 124ms | 12476kb | C++20 | 2.5kb | 2023-12-15 17:55:08 | 2023-12-15 17:55:08 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
template <class... T> void dbg(T... x) { char e{}; ((cerr << e << x, e = ' '), ...); }
template <class T> void org(T l, T r) { while (l != r) cerr << ' ' << *l++; cerr << '\n'; }
#define debug(x...) dbg(#x, '=', x, '\n')
#define olist(x...) dbg(#x, '='), org(x)
#else
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define debug(...) ((void)0)
#define olist(...) ((void)0)
#endif
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define ff first
#define ss second
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using Pt = pair<int, int>;
template <class T> inline constexpr T inf = numeric_limits<T>::max() / 2;
constexpr int mod = 998244353;
template<class T> bool chmin(T &a, T b) { return (b < a and (a = b, true)); }
template<class T> bool chmax(T &a, T b) { return (a < b and (a = b, true)); }
template<class... T> int add(T... x) { int t{}; return (((t += x) %= mod), ...), t; }
template<class... T> int mul(T... x) { i64 t{1}; return (((t *= x) %= mod), ...), t; }
template<size_t N>
struct Sieve {
array<bool, N + 1> isp{};
array<int, N + 1> mu{}, phi{};
vector<int> primes{};
Sieve() {
isp.fill(true);
isp[0] = isp[1] = false;
mu[1] = 1;
phi[1] = 1;
for (int i = 2; i <= N; i++) {
if (isp[i]) {
primes.push_back(i);
mu[i] = -1;
phi[i] = i - 1;
}
for (i64 p : primes) {
if (p * i > N) break;
isp[p * i] = false;
if (i % p == 0) {
phi[p * i] = phi[i] * p;
break;
}
phi[p * i] = phi[i] * (p - 1);
mu[p * i] = mu[p] * mu[i];
}
}
}
};
Sieve<int(1e6)> sie;
int power(int a, int b) {
int r = 1;
for (; b; b >>= 1, a = mul(a, a))
if (b & 1) r = mul(r, a);
return r;
};
void solve() {
int m, k;
cin >> m >> k;
int ans = 0;
for (int i = 1; i <= k; i++) {
int t = k / i * 2 + 1;
t = add(power(t, m), mod - 1);
ans = add(ans, mul(t, mod + sie.mu[i]));
}
ans = add(ans, 1);
cout << ans << '\n';
}
signed main() {
cin.tie(0)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int T = 1;
// cin >> T;
while (T--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 9ms
memory: 12472kb
input:
2 1
output:
9
result:
ok single line: '9'
Test #2:
score: 0
Accepted
time: 4ms
memory: 12432kb
input:
2 2
output:
17
result:
ok single line: '17'
Test #3:
score: 0
Accepted
time: 7ms
memory: 12436kb
input:
10000 10000
output:
689223145
result:
ok single line: '689223145'
Test #4:
score: 0
Accepted
time: 9ms
memory: 12436kb
input:
9999 31
output:
986106162
result:
ok single line: '986106162'
Test #5:
score: 0
Accepted
time: 6ms
memory: 12420kb
input:
57 9817
output:
447253096
result:
ok single line: '447253096'
Test #6:
score: 0
Accepted
time: 8ms
memory: 12376kb
input:
501 499
output:
247755220
result:
ok single line: '247755220'
Test #7:
score: 0
Accepted
time: 25ms
memory: 12460kb
input:
97424 174829
output:
964884269
result:
ok single line: '964884269'
Test #8:
score: 0
Accepted
time: 9ms
memory: 12428kb
input:
11 13
output:
729153057
result:
ok single line: '729153057'
Test #9:
score: 0
Accepted
time: 27ms
memory: 12392kb
input:
200000 200000
output:
803771125
result:
ok single line: '803771125'
Test #10:
score: 0
Accepted
time: 9ms
memory: 12476kb
input:
199999 562
output:
865836540
result:
ok single line: '865836540'
Test #11:
score: 0
Accepted
time: 18ms
memory: 12432kb
input:
3539 189423
output:
530738158
result:
ok single line: '530738158'
Test #12:
score: 0
Accepted
time: 28ms
memory: 12416kb
input:
198324 173852
output:
963717515
result:
ok single line: '963717515'
Test #13:
score: 0
Accepted
time: 9ms
memory: 12384kb
input:
1 1
output:
3
result:
ok single line: '3'
Test #14:
score: 0
Accepted
time: 124ms
memory: 12400kb
input:
1000000 1000000
output:
800590912
result:
ok single line: '800590912'
Test #15:
score: 0
Accepted
time: 81ms
memory: 12408kb
input:
5034 999999
output:
946555033
result:
ok single line: '946555033'
Test #16:
score: 0
Accepted
time: 6ms
memory: 12440kb
input:
999998 2042
output:
713878368
result:
ok single line: '713878368'