QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#747618 | #9622. 有限小数 | IllusionaryDominance# | WA | 0ms | 3596kb | C++20 | 1.3kb | 2024-11-14 17:41:44 | 2024-11-14 17:41:45 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e9;
ll a, b, c, d;
set <ll> vis;
void upd(ll c_, ll d_) {
ll y = __gcd(c_, d_);
if (c_ / y < c && d_ / y <= INF) {
c = c_ / y; d = d_ / y;
}
}
void dfs(ll s) {
if (vis.find(s) != vis.end()) return ;
vis.insert(s);
ll g = __gcd(s, b);
ll x = b / g * s;
if (s > INF) return ;
ll tmp = s / g * a;
ll t = (tmp - 1) / (b / g) + 1;
ll c_ = b / g * t - tmp;
if (s % 10 == 0) {
if (t % 10 == 4) {
upd(c_ + (b / g) * 3, x);
}else if (t % 10 == 5) {
upd(c_ + (b / g) * 2, x);
}else if (~ t & 1) {
upd(c_ + (b / g), x);
}else {
upd(c_, x);
}
}else if (~ s & 1) {
if (s & 1) upd(c_, x);
else upd(c_ + (b / g), x);
}else if (s == 1) {
upd(c_, x);
}else {
if (t % 5 == 0) upd(c_ + (b / g), x);
else upd(c_, x);
}
dfs(s << 1);
dfs(s * 5);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int T;
cin >> T;
while (T --) {
cin >> a >> b;
c = b - a; d = b;
vis.clear(); dfs(1);
cout << c << ' ' << d << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3596kb
input:
4 1 2 2 3 3 7 19 79
output:
1 2 1 3 1 14 3 316
result:
wrong answer Jury found better answer than participant's 0 < 1 (Testcase 1)