QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#106791 | #3161. Another Coin Weighing Puzzle | skittles1412 | AC ✓ | 114ms | 7412kb | C++17 | 3.2kb | 2023-05-19 09:11:19 | 2023-05-19 09:11:21 |
Judging History
answer
#include "bits/extc++.h"
using namespace std;
template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
cerr << t;
((cerr << " | " << u), ...);
cerr << endl;
}
#ifdef DEBUG
#define dbg(...) \
cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]: "; \
dbgh(__VA_ARGS__)
#else
#define dbg(...)
#define cerr \
if (false) \
cerr
#endif
#define endl "\n"
#define long int64_t
#define sz(x) int(std::size(x))
struct mint {
static constexpr int MOD = 998244353;
static constexpr mint pow(mint base, long exp) {
mint ans = 1;
while (exp) {
if (exp & 1) {
ans *= base;
}
base *= base;
exp >>= 1;
}
return ans;
}
static constexpr int norm(long x) {
x %= MOD;
if (x < 0) {
x += MOD;
}
return int(x);
}
int x;
constexpr mint() : x(0) {}
constexpr mint(long x) : x(norm(x)) {}
static constexpr mint from_unchecked(int x) {
mint m;
m.x = x;
return m;
}
friend ostream& operator<<(ostream& out, mint m) {
return out << m.x;
}
mint operator-() const {
if (!x) {
return 0;
}
return from_unchecked(MOD - x);
}
mint& operator+=(const mint& m) {
x += m.x;
if (x >= MOD) {
x -= MOD;
}
return *this;
}
mint& operator-=(const mint& m) {
return *this += -m;
}
mint& operator*=(const mint& m) {
x = int(long(x) * m.x % MOD);
return *this;
}
friend mint operator+(mint a, const mint& b) {
return a += b;
}
friend mint operator-(mint a, const mint& b) {
return a -= b;
}
friend mint operator*(mint a, const mint& b) {
return a *= b;
}
};
int n, m, ans = 0;
vector<int> carr;
void dfs(int ind) {
if (ind == n) {
int g = 0;
for (auto& a : carr) {
g = gcd(g, a);
}
ans += g == 0 || g == 1;
return;
}
for (int i = -m; i <= m; i++) {
carr.push_back(i);
dfs(ind + 1);
carr.pop_back();
}
}
void solve() {
cin >> n >> m;
mint dp[m + 1] {};
for (int i = m; i >= 1; i--) {
dp[i] = mint::pow(2 * (m / i) + 1, n) - 1;
for (int j = 2 * i; j <= m; j += i) {
dp[i] -= dp[j];
}
}
cout << dp[1] + 1 << endl;
// dfs(0);
// cout << ans << endl;
// mint p = 0;
// for (int i = 1; i <= m; i++) {
// for (int j = 1; j <= m; j++) {
// p += gcd(i, j) == 1;
// }
// }
// mint dp[2][n + 1] {};
// dp[0][0] = dp[1][0] = 1;
// for (int i = 1; i <= n; i++) {
// dp[0][i] = dp[0][i - 1] + 2 * dp[1][i - 1];
// dp[1][i] = dp[1][i - 1] + 2 * p * mint::pow(2 * m + 1, i - 1);
// }
// cout << dp[0][n] << endl;
}
int main() {
cin.tie(nullptr);
cin.exceptions(ios::failbit);
ios_base::sync_with_stdio(false);
solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3384kb
input:
2 1
output:
9
result:
ok single line: '9'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3292kb
input:
2 2
output:
17
result:
ok single line: '17'
Test #3:
score: 0
Accepted
time: 3ms
memory: 3380kb
input:
10000 10000
output:
689223145
result:
ok single line: '689223145'
Test #4:
score: 0
Accepted
time: 2ms
memory: 3516kb
input:
9999 31
output:
986106162
result:
ok single line: '986106162'
Test #5:
score: 0
Accepted
time: 2ms
memory: 3424kb
input:
57 9817
output:
447253096
result:
ok single line: '447253096'
Test #6:
score: 0
Accepted
time: 2ms
memory: 3412kb
input:
501 499
output:
247755220
result:
ok single line: '247755220'
Test #7:
score: 0
Accepted
time: 17ms
memory: 3976kb
input:
97424 174829
output:
964884269
result:
ok single line: '964884269'
Test #8:
score: 0
Accepted
time: 2ms
memory: 3328kb
input:
11 13
output:
729153057
result:
ok single line: '729153057'
Test #9:
score: 0
Accepted
time: 25ms
memory: 4036kb
input:
200000 200000
output:
803771125
result:
ok single line: '803771125'
Test #10:
score: 0
Accepted
time: 2ms
memory: 3328kb
input:
199999 562
output:
865836540
result:
ok single line: '865836540'
Test #11:
score: 0
Accepted
time: 15ms
memory: 4080kb
input:
3539 189423
output:
530738158
result:
ok single line: '530738158'
Test #12:
score: 0
Accepted
time: 19ms
memory: 4064kb
input:
198324 173852
output:
963717515
result:
ok single line: '963717515'
Test #13:
score: 0
Accepted
time: 2ms
memory: 3520kb
input:
1 1
output:
3
result:
ok single line: '3'
Test #14:
score: 0
Accepted
time: 114ms
memory: 7144kb
input:
1000000 1000000
output:
800590912
result:
ok single line: '800590912'
Test #15:
score: 0
Accepted
time: 83ms
memory: 7412kb
input:
5034 999999
output:
946555033
result:
ok single line: '946555033'
Test #16:
score: 0
Accepted
time: 3ms
memory: 3404kb
input:
999998 2042
output:
713878368
result:
ok single line: '713878368'