QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#364737 | #3161. Another Coin Weighing Puzzle | chuchu# | WA | 1ms | 3652kb | C++23 | 937b | 2024-03-24 16:18:48 | 2024-03-24 16:18:49 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll P = 998244353;
ll qpow(ll a, ll b) {
ll ans = 1;
for(; b; b/=2, a = a * a % P) {
if(b%2==1) ans = ans * a % P;
}
return ans;
}
void solve() {
ll m, k; cin >> m >> k;
vector<ll>dp(k+1);
vector<bool>vis(k+1);
for(int i = 1 ; i <= k ; i ++) {
dp[i] = qpow(2*i+1, m);
}
vis[1] = true;
function<int(int)>calc = [&](int u)->int{
if(vis[u]) return dp[u];
for(int d = 2 ; d <= u ; ) {
int k = u / d;
int nxt = min(u, u/k);
dp[u] = (dp[u] - (calc(k) - 1) * (nxt-d+1)) % P;
d = nxt+1;
}
vis[u] = true;
return dp[u];
};
cout << (calc(k) + P) % P << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3632kb
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: -100
Wrong Answer
time: 1ms
memory: 3652kb
input:
10000 10000
output:
873772547
result:
wrong answer 1st lines differ - expected: '689223145', found: '873772547'