QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#737091 | #9622. 有限小数 | isaunoya | WA | 51ms | 3632kb | C++23 | 2.3kb | 2024-11-12 14:36:34 | 2024-11-12 14:36:37 |
Judging History
answer
#if defined(local)
#include "./noya/debug.hpp"
#else
#define debug(...) 42
#endif
#include "bits/stdc++.h"
using namespace std;
#define rep1(a) for (int i = 0; i < a; i++)
#define rep2(i, a) for (int i = 0; i < a; i++)
#define rep3(i, a, b) for (int i = a; i < b; i++)
#define rep4(i, a, b, c) for (int i = a; i < b; i += c)
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define pb emplace_back
template <typename T, typename T2> void cmin(T &x, const T2 &y) {
x = x < y ? x : y;
}
template <typename T, typename T2> void cmax(T &x, const T2 &y) {
x = x > y ? x : y;
}
#include <cstdint>
using ll = int64_t;
using ull = uint64_t;
namespace noya {
template <class T> constexpr T infty = 0;
template <> constexpr int infty<int> = 1010000000;
template <> constexpr ll infty<ll> = 2020000000000000000;
template <> constexpr unsigned infty<unsigned> = infty<int>;
template <>
constexpr ull infty<ull> = infty<ll>;
template <>
constexpr __int128 infty<__int128> =
__int128(infty<ll>) * 2000000000000000000;
template <> constexpr double infty<double> = infty<ll>;
template <> constexpr long double infty<long double> = infty<ll>;
} // namespace noya
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T> using vc = vector<T>;
const int INF = 1010000000;
const ll LNF = 1010000000000000000;
#define sz(x) int((x).size())
#define all(x) begin(x), end(x)
#define fi first
#define se second
namespace noya {}
const int L = 1e9;
void solve() {
ll a, b;
cin >> a >> b;
ll w = b;
while (w % 2 == 0)
w /= 2;
while (w % 5 == 0)
w /= 5;
array<ll, 2> ans = {b - a, b};
if (w == 1) {
ans = {0, 1};
} else {
for (ll m2 = 1; b * m2 <= L; m2 *= 2) {
for (ll m5 = 1; b * m2 * m5 <= L; m5 *= 5) {
ll m = m2 * m5;
ll A = m * a;
ll B = m * b;
array<ll, 2> cur{w - A % w, B};
ll g = gcd(cur[0], cur[1]);
cur[0] /= g;
cur[1] /= g;
if (cur < ans) {
ans = cur;
}
}
}
}
cout << ans[0] << " " << ans[1] << "\n";
}
int main() {
int T;
cin >> T;
while (T--)
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3632kb
input:
4 1 2 2 3 3 7 19 79
output:
0 1 1 3 1 14 3 316
result:
ok 4 case(s)
Test #2:
score: -100
Wrong Answer
time: 51ms
memory: 3632kb
input:
10000 11 12 28 53 17 60 2 35 17 181 80 123 68 141 79 163 71 99 13 64 33 61 15 32 16 61 11 86 33 74 128 143 40 53 7 23 30 31 5 6 86 181 73 91 13 23 71 81 1 2 7 38 117 160 33 83 129 151 88 153 25 58 16 19 19 141 95 124 43 96 71 139 11 59 106 109 93 152 34 43 17 99 1 57 20 159 16 25 5 73 159 170 172 17...
output:
1 12 1 54272 1 60 1 7 1 231680000 23 3936 1 36096000 5 326 1 63360 0 1 1 31232 0 1 1 4880 1 10750 1 18500 1 11714560 1 331250 1 2944 1 31 1 6 1 289600000 1 455000 1 58880 1 51840 0 1 1 304 0 1 1 415 1 19328000 1 765000000 1 4640 1 608 1 72192 3 775 1 48 3 347500 1 944 1 43600 1 76 1 430000 1 6336 1 ...
result:
wrong answer Jury found better answer than participant's 1 < 2 (Testcase 8812)