QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#749413#9622. 有限小数HirroWA 0ms3644kbC++201.4kb2024-11-15 00:29:432024-11-15 00:29:44

Judging History

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

  • [2024-11-15 00:29:44]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3644kb
  • [2024-11-15 00:29:43]
  • 提交

answer

#include"bits/stdc++.h"
#define endl '\n'
#define int ll
using ll = long long;
using namespace std;
constexpr int N = 1e5 + 10, inf = 0X3F3F3F3F, U = 1e9;
constexpr ll INF = 0X3F3F3F3F3F3F3F3F;
int ex_gcd(int a, int b, int& x, int& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    int d = ex_gcd(b, a % b, x, y);
    int temp = x;
    x = y;
    y = temp - a / b * y;
    return d;
}

bool liEu(int a, int b, int c, int& x, int& y) {
    int d = ex_gcd(a, b, x, y);
    if (c % d != 0) return 0;
    int k = c / d;
    x *= k;
    y *= k;
    return 1;
}
void solve() {
    int a, b;
    cin >> a >> b;
    int w = b;
    while (w % 2 == 0)
        w /= 2;
    while (w % 5 == 0)
        w /= 5;
    int rc = INF, rd;
    for (int i = w; i <= U; i *= 2) {
        for (int j = i; j <= U; j *= 5) {
            int d = j;
            ll A = -b, B = b*d, C = a * d;
            ll x, y;
            if (liEu(A, B, C, x, y) == 0)
                continue;
            ll t = B / gcd(A, B);
            ll c = (x % t + t) % t;
            if (c < rc and d >= 1 and d <= U) {
                rc = c;
                rd = d;
            }
        }
    }
    cout << rc << ' ' << rd << endl;
}
signed main() {
    cin.tie(nullptr)->sync_with_stdio(0);
    int t; cin >> t; while (t--)
        solve();
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3644kb

input:

4
1 2
2 3
3 7
19 79

output:

1 2
1 3
4 7
60 79

result:

wrong answer Jury found better answer than participant's 0 < 1 (Testcase 1)