QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#743081 | #9622. 有限小数 | chatoyane | WA | 0ms | 3600kb | C++20 | 1.3kb | 2024-11-13 18:10:32 | 2024-11-13 18:10:33 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using db = double;
#define endl '\n'
const LL inf = 1e18;
void solve()
{
LL a, b;
cin >> a >> b;
auto check = [&](int x) -> bool
{
while (x % 2 == 0)
x /= 2;
while (x % 5 == 0)
x /= 5;
return (x == 1);
};
if (check(b))
{
cout << "0 1" << endl;
return;
}
LL d = b;
while (d % 2 == 0)
d /= 2;
while (d % 5 == 0)
d /= 5;
LL ans1 = 1e18, ans2 = 1e18;
for (LL pw2 = 1; pw2 * b <= 1e18; pw2 *= 2)
{
for (LL pw5 = 1; pw5 * pw2 * b <= 1e18; pw5 *= 5)
{
LL k = pw2 * pw5;
LL c = (d - (a * k) % d) % d;
LL g = gcd(c, b * k);
LL c1 = c / g, d1 = b * k / g;
if (c1 < ans1)
{
ans1 = c1, ans2 = d1;
}
// ans = min(ans, c);
}
}
// if (ans1 == 193)
// {
// cerr << "a = " << a << " b = " << b << endl;
// }
// if (ans1 == 193)
// cout << a << endl;
cout << ans1 << " " << ans2 << endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while (T--)
solve();
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3600kb
input:
4 1 2 2 3 3 7 19 79
output:
0 1 1 3 1 4375 3 1506805419921875
result:
wrong answer Integer 1506805419921875 violates the range [1, 10^9]