QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#736439#9622. 有限小数xiangguiRE 0ms0kbC++141.6kb2024-11-12 11:05:492024-11-12 11:05:50

Judging History

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

  • [2024-11-12 11:05:50]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-12 11:05:49]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long

using namespace std;

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

// bool getans(int cur2) {
//     int x, y;
//     exgcd()
// }

void solve() {
    int a, b;
    scanf("%lld%lld", &a, &b);
    int cur = 1;
    int ans = 1000000000, ans2 = 0;
    // int 
    auto getans = [&b, &a](int cur2) -> int {
        int x, y;
        // cerr << b << ' ' << 1 << '\n';
        exgcd(b, 1, x, y);
        y = -y;
        // cerr << x << ' ' << y << '\n';
        x *= cur2 * a;
        y *= cur2 * a;
        
        // cerr << x << ' ' << y << '\n';
        y %= b;
        y += b;
        y %= b;
        // cerr << y << '\n';
        return y;
    };
    for (int i = 0; i <= 20; ++i) {
        // int cu
        int cur2 = cur;
        for (int j = 0; j <= 20; ++j) {
            // if (cur2 == 2) cerr << 1 <000000000< '\n';
            int tmp = getans(cur2);
            // if (cur2 == 2) cerr << tmp << '\n';
            if (tmp < ans) {
                // cerr << cur2 << ' ' << tmp << '\n';
                ans = tmp;
                ans2 = cur2 * b;
            }
            // ans = min(ans, getans(cur2));
            if (cur2 > 1000000000 / (5 * b)) break;
            cur2 *= 5;
        }
        if (cur > 1000000000 / (2 * b)) break;
        cur *= 2;
    }
    printf("%lld %lld\n", ans, ans2);
}

signed main() {
    int T;
    scanf("%lld", &T);
    while (T--) {
        solve();
    }
    return 0;
}

详细

Test #1:

score: 0
Runtime Error

input:

4
1 2
2 3
3 7
19 79

output:


result: