QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#769805 | #9622. 有限小数 | 333zhan# | Compile Error | / | / | C++20 | 1.3kb | 2024-11-21 19:27:20 | 2024-11-21 19:27:21 |
Judging History
This is the latest submission verdict.
- [2024-11-21 19:27:21]
- Judged
- Verdict: Compile Error
- Time: 0ms
- Memory: 0kb
- [2024-11-21 19:27:20]
- Submitted
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
constexpr int inf = 1E18;
constexpr int N = 1E9;
using i9 = __int128;
vector <int> f;
set <int> st;
void solve () {
int a, b;
cin >> a >> b;
if (a == b || st.find (b) != st.end ()) {
cout << 0 << " " << 1 << '\n';
return;
}
int C = -1, D;
for (auto x : f) {
auto check = [&] (int t) {
return i9(a) * x <= i9(b) * t;
};
int l = 1, r = inf;
while (l < r) {
int mid = (l + r) / 2;
if (check (mid)) {
r = mid;
} else {
l = mid + 1;
}
}
i9 c = i9(l) * b - i9(a) * x;
i9 d = i9(x) * b;
i9 gc = gcd (c, d);
c /= gc;
d /= gc;
if (d <= N && (C == -1 || C > c)) {
C = c;
D = d;
}
}
cout << C << " " << D << '\n';
}
signed main () {
ios::sync_with_stdio (false);
cin.tie (nullptr);
for (i9 i = 1; i <= inf; i *= 2) {
for (i9 j = i; j <= inf; j *= 5) {
f.push_back (j);
st.insert (j);
}
}
int T = 1;
cin >> T;
while (T --) {
solve ();
}
return 0;
}
Details
In file included from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:58, from answer.code:1: /usr/include/c++/13/numeric: In instantiation of ‘constexpr std::common_type_t<_Tp1, _Tp2> std::gcd(_Mn, _Nn) [with _Mn = __int128; _Nn = __int128; common_type_t<_Tp1, _Tp2> = __int128]’: answer.code:39:21: required from here /usr/include/c++/13/numeric:166:21: error: static assertion failed: std::gcd arguments must be integers 166 | static_assert(is_integral_v<_Mn> && is_integral_v<_Nn>, | ^~~~~~~~~~~~~~~~~~ /usr/include/c++/13/numeric:166:21: note: ‘std::is_integral_v<__int128>’ evaluates to false In file included from /usr/include/c++/13/bits/stl_pair.h:60, from /usr/include/c++/13/bits/stl_algobase.h:64, from /usr/include/c++/13/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51: /usr/include/c++/13/type_traits: In instantiation of ‘struct std::make_unsigned<__int128>’: /usr/include/c++/13/type_traits:1983:11: required by substitution of ‘template<class _Tp> using std::make_unsigned_t = typename std::make_unsigned::type [with _Tp = __int128]’ /usr/include/c++/13/numeric:173:24: required from ‘constexpr std::common_type_t<_Tp1, _Tp2> std::gcd(_Mn, _Nn) [with _Mn = __int128; _Nn = __int128; common_type_t<_Tp1, _Tp2> = __int128]’ answer.code:39:21: required from here /usr/include/c++/13/type_traits:1836:62: error: invalid use of incomplete type ‘class std::__make_unsigned_selector<__int128, false, false>’ 1836 | { typedef typename __make_unsigned_selector<_Tp>::__type type; }; | ^~~~ /usr/include/c++/13/type_traits:1744:11: note: declaration of ‘class std::__make_unsigned_selector<__int128, false, false>’ 1744 | class __make_unsigned_selector; | ^~~~~~~~~~~~~~~~~~~~~~~~