QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#687781 | #6440. Xingqiu's Joke | RimuruChan | WA | 264ms | 3716kb | C++23 | 1.4kb | 2024-10-29 21:12:14 | 2024-10-29 21:12:15 |
Judging History
answer
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#include "debug.h"
#else
#define dbg(...) (void)0
#endif
using u32 = unsigned int;
using i64 = long long;
namespace skadi {
std::vector<i64> getd(i64 x) {
std::vector<i64> d;
for (i64 i = 2; i * i <= x; i++) {
if (x % i == 0) {
d.push_back(i);
while (x % i == 0) x /= i;
}
}
if (x > 1) d.push_back(x);
return d;
}
void solve() {
i64 a, b;
std::cin >> a >> b;
if (a > b) std::swap(a, b);
i64 delta = b - a;
std::vector<i64> d = getd(delta);
std::map<std::pair<i64, i64>, i64> cnt;
auto dfs = [&](auto&& self, i64 x, i64 delta) -> i64 {
if (x == 1) return 0;
if (cnt.count({x, delta})) return cnt[{x, delta}];
if (delta == 1) return cnt[{x, delta}] = x - 1;
i64 min = 1e9;
for (i64 p : d) {
if (delta % p != 0) continue;
i64 l = x % p;
i64 a = l + 1 + self(self, x / p, delta / p);
i64 b = p - l + 1 + self(self, (x + p - 1) / p, delta / p);
min = std::min({min, a, b});
}
return cnt[{x, delta}] = min;
};
std::cout << dfs(dfs, a, delta) << '\n';
}
} // namespace skadi
int main() {
#ifndef LOCAL_DEBUG
std::cin.tie(nullptr)->sync_with_stdio(false);
#endif
int t = 1;
std::cin >> t;
while (t--) {
skadi::solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3616kb
input:
5 4 7 9 8 32 84 11 35 2 1
output:
2 7 5 4 0
result:
ok 5 number(s): "2 7 5 4 0"
Test #2:
score: -100
Wrong Answer
time: 264ms
memory: 3716kb
input:
300 223528529 446621399 755625805 978718675 257717538 480810408 277875777 54782907 963091558 739998688 282469431 505562301 38752451 261845321 474429597 697522467 67026335 290119205 874629705 651536835 301964126 78871256 316864911 93772041 545942587 322849717 640801578 417708708 683070559 906163429 9...
output:
12 19 15 17 16 17 13 19 15 17 15 16 18 17 17 19 15 18 15 16 17 18 19 15 17 17 17 13 19 16 13 19 16 15 13 18 17 18 16 15 14 17 14 16 15 14 19 18 16 14 16 17 16 18 14 16 17 14 18 17 16 19 19 18 17 16 16 14 23 14 14 18 18 20 16 16 17 17 12 18 19 17 16 18 16 16 18 12 15 18 16 13 19 18 16 18 17 15 13 16 ...
result:
wrong answer 12th numbers differ - expected: '15', found: '16'