QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#791905 | #9622. 有限小数 | UESTC_DECAYALI# | WA | 0ms | 3512kb | C++20 | 1.4kb | 2024-11-28 21:52:03 | 2024-11-28 21:52:27 |
Judging History
answer
#include <bits/stdc++.h>
using i128 = __int128_t;
using llsi = long long;
i128 p2[41] = {1}, p5[41] = {1};
i128 w;
i128 exgcd(i128 a, i128 b, i128 &x, i128 &y) {
if (0==b) { x = 1; y = 0; return a; }
i128 ret = exgcd(b, a % b, y, x);
y -= a / b * x;
return ret;
}
i128 calc(i128 a, i128 b, i128 c) {
i128 x0, y0;
i128 g = exgcd(a, b, x0, y0);
// assert(a * x0 + b * y0 == g);
if (c % g != 0) return -1;
x0 *= c / g, y0 *= c / g;
i128 val = abs(llsi(b / g));
x0 = (x0 % val + val) % val;
if (0 == x0) x0 = val;
return x0;
}
void work() {
llsi a, b; std::cin >> a >> b;
llsi c, d = -1;
for(int x = 0; x <= 30; ++x) for(int y = 0; y <= 13; ++y) {
if(b * w % (p2[x] * p5[y]) != 0) break;
llsi nd = b * w / (p2[x] * p5[y]), nc = calc(- p2[x] * p5[y], b, a * w);
if(nc < 0) continue;
if(nd > 1'000'000'000) continue;
// std::cerr << std::format("x = {}, y = {}, c = {}, d = {}\n", p2[x], p5[y], nc, nd);
if(d < 0 || nc < c) c = nc, d = nd;
}
std::cout << c << " " << d << std::endl;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr), std::cout.tie(nullptr);
for(int i = 1; i <= 40; ++i) p2[i] = p2[i - 1] * 2, p5[i] = p5[i - 1] * 5;
w = p2[2] * p5[2];
// std::cout << llsi(w) << char(10);
int T; std::cin >> T; while(T--) work();
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3512kb
input:
4 1 2 2 3 3 7 19 79
output:
1 100 1 300 1 700 3 316
result:
wrong answer Jury found better answer than participant's 0 < 1 (Testcase 1)