QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#740492 | #9622. 有限小数 | qzhfx | WA | 1ms | 3536kb | C++23 | 1.9kb | 2024-11-13 10:08:26 | 2024-11-13 10:08:27 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 7;
const int mod = 998244353;
// #define int __int128
std::vector<int> vc;
void solve()
{
ll a, b;
cin >> a >> b;
int aa = a, bb = b;
ll c = 1e9, d = 1e9;
ll k = 1;
ll p = b;
while(p%2==0){
p/=2;
k *=2;
}
while(p%5==0){
p/=5;
k *=5;
}
for (auto x : vc)
{
int l = 0, r = x;
auto check = [&](int mid)
{
double ab = 1.0 * a / b;
double now = 1.0 * mid / x;
if (now < ab)
return false;
else
return true;
};
while (l < r)
{
int mid = l + r >> 1;
if (check(mid))
r = mid;
else
l = mid + 1;
}
ll lt = b * l, at = x * a * k;
__int128 gf = b * x;
__int128 tal = lt - at;
ll gc = __gcd(gf, tal);
gf /= gc;
tal /= gc;
// int bb = b;
// int gc = __gcd(bb, x);
// int gf = bb / gc * x;
// int tal = l * bb / gc - aa * x / gc;
// gc = __gcd(tal, gf);
// tal /= gc, gf /= gc;
if (tal < c && gf <= 1e9 && gf >= 1)
{
c = tal, d = gf;
}
}
if (c == 1e9 || c == 0)
{
cout << 0 << ' ' << 1 << '\n';
return;
}
cout << c << ' ' << d << '\n';
}
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
for (int now = 1; now <= 1e9; now *= 2)
for (int tmp = 1; tmp <= 1e9; tmp *= 5)
{
ll sum = tmp * now;
if (sum > 1e9)
continue;
vc.push_back(now * tmp);
}
sort(vc.begin(), vc.end());
ll _ = 1;
cin >> _;
while (_--)
solve();
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3536kb
input:
4 1 2 2 3 3 7 19 79
output:
-122070312 244140625 -2 3 -3 7 1 497025024
result:
wrong answer Integer -122070312 violates the range [0, 10^9]