QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#764238#9622. 有限小数superguymjCompile Error//Python31.6kb2024-11-20 08:13:222024-11-20 08:13:22

Judging History

你现在查看的是最新测评结果

  • [2024-11-20 08:13:22]
  • 评测
  • [2024-11-20 08:13:22]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(i,x,y) for (int i = x; i <= y; i++)
#define repd(i,x,y) for (int i = x; i >= y; i--)
#define mid ((l + r) >> 1)
#define lch (rt << 1)
#define rch (rt << 1 | 1)

using namespace std;

using u32 = unsigned;
using i64 = long long;
using u64 = unsigned long long;

int exgcd(int a, int b, int& x, int& y) {
    if (!b) {
        x = 1, y = 0;
        return a;
    }
    int g = exgcd(b, a % b, y, x);
    y -= a / b * x;
    return g;
}

void solve() {
    int a, b;
    cin >> a >> b;
    a %= b;

    int p = b;
    while (p % 2 == 0) {
        p /= 2;
    }
    while (p % 5 == 0) {
        p /= 5;
    }
    a = (-a % p + p) % p;
    
    int x, y;
    exgcd(p, b / p, x, y);
    a = (1LL * a * y % p + p) % p;
    b = p;

    int c = a, d = b;


    constexpr int inf = 1E9;

    i64 A = a, B = b;
    rep(i,0,50) {
        i64 _A = A, _B = B;
        rep(j,0,50) {
            _A = _A * 5 % p;
            _B = _B * 5;
            if (_B > inf) {
                break;
            }
            if (_A < c) {
                c = _A;
                d = _B;
            }
        }
        A = A * 2 % p;
        B = B * 2;

        if (B > inf) {
            break;
        }
        if (A < c) {
            c = A;
            d = B;
        }
    }

    cout << c << ' ' << d << '\n';
    // cout << c << '\n';
}

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

    int T;
    cin >> T;

    while (T--) {
        solve();
    }

    return 0;
}

详细

  File "answer.code", line 40
    a = (1LL * a * y % p + p) % p;
         ^
SyntaxError: invalid decimal literal