QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#716246 | #6440. Xingqiu's Joke | jty233 | WA | 199ms | 3768kb | C++23 | 2.6kb | 2024-11-06 14:44:01 | 2024-11-06 14:44:01 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using i64 = long long;
#define int long long
int check(int x) {
int ans = 0ll;
for(int i = 2; i * i <= x; i++) {
while(x % i == 0) {
ans++;
x /= i;
}
}
if(x > 1) ans++;
return ans;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--){
int a, b;
cin >> a >> b;
if(a > b) swap(a, b);
int c = b - a;
if(c == 0) {
throw std::runtime_error("humorous data");
}
if(c == 1){
cout << a - 1 << '\n';
continue;
}
vector<int> fac;
for(int i=2; i*i<=c; i++){
if(c % i == 0){
fac.push_back(i);
while(c % i == 0) c /= i;
}
}
if(c > 1) fac.push_back(c);
sort(fac.begin(), fac.end());
c = b - a;
// unordered_map<int, int> rcd;
// rcd[1] = 0; rcd[0] = 1e9;
// auto dfs = [&](auto&&dfs, int a)->int{
// if(rcd.count(a)) return rcd[a];
// int ans = a - 1;
// for(auto p : fac){
// auto x = a % p;
// ans = min(ans, dfs(dfs, a/p) + a % p + 1);
// if(a % p > 0){
// ans = min(ans, dfs(dfs, a/p + 1) + p - a % p + 1);
// }
// }
// // cout << format("rcd[{}] = {}\n", a, ans);
// return rcd[a] = ans;
// };
// cout << dfs(dfs, a) << '\n';
unordered_set<int> vis;
priority_queue<array<int, 3>, vector<array<int, 3>>, greater<>> q;
q.push({0, a, c});
int ans = 0x7ffffffffffll;
while(!q.empty()){
auto [d, u, ct] = q.top(); q.pop();
if(u == 0) {
throw std::runtime_error("humorous code");
}
if(d >= ans) {
break;
} else {
ans = std::min(ans, d + u - 1);
}
if(u == 1) {
break;
}
if(vis.count(u)) continue;
vis.insert(u);
for(auto p : fac){
if(ct % p != 0) {
continue;
}
if(u >= p) {
q.push({d + u % p + 1, u / p, ct / p});
}
q.push({d + p - u % p + 1, u / p + 1, ct / p});
}
}
cout << ans << endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3540kb
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: 199ms
memory: 3768kb
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 15 18 17 17 19 14 18 15 16 17 18 19 15 17 17 17 12 19 16 12 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 15 18 12 15 18 16 12 19 18 15 18 17 14 13 16 ...
result:
wrong answer 161st numbers differ - expected: '14', found: '15'