QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#760264#9622. 有限小数1205691775#Compile Error//C++201.3kb2024-11-18 15:53:012024-11-18 15:53:02

Judging History

This is the latest submission verdict.

  • [2024-11-18 15:53:02]
  • Judged
  • [2024-11-18 15:53:01]
  • Submitted

answer

#include <bits/stdc++.h>

using i64 = long long;
constexpr int fk_max = 1e9;
void solve(){
    i64 a, b;
    std::cin >> a >> b;
    i64 remb = b;
    while(remb % 2 == 0){
        remb /= 2;
    }
    while(remb % 5 == 0) {
        remb /= 5;
    }


    i64 c = 1e18, d = 1e18;

    i64 cx_a = a % remb;
    if (cx_a == 0) {
        std::cout << "0 1\n";
        return;
    }
    for(i64 i = 1; i <= 1e16; i = i * 2) {
        i64 cx_b = cx_a;
        for (i64 j = i; j <= 1e16; j *= 5) {
            // j * b = fm
            // std::cout << j << "!\n";
            i64 rem = remb - cx_b;
            __int128 cc = rem;
            __int128 dd = j * b;
            __int128 g = std::gcd(cc, dd);
            cc /= g;
            dd /= g;
            if (dd <= fk_max) {
                if (cc < c) {
                    c = cc;
                    d = dd;
                } else if (cc == c) {
                    d = std::min(i64(dd), d);
                }
            }
            cx_b = cx_b * 5 % remb;
        }
        cx_a = cx_a * 2 % remb;
    }
    std::cout << c << " " << d << "\n";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);


    int t;
    std::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:32:34:   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:32:34:   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;
      |           ^~~~~~~~~~~~~~~~~~~~~~~~