QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#748221#9622. 有限小数mapleKingWA 0ms3752kbC++201.3kb2024-11-14 19:44:372024-11-14 19:44:37

Judging History

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

  • [2024-11-14 19:44:37]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3752kb
  • [2024-11-14 19:44:37]
  • 提交

answer

#include <bits/stdc++.h>
#pragma GCC optimize(2)

// using namespace std;

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

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

void solve() {
    i64 a, b;
    std::cin >> a >> b;
    i64 b2 = b;
    while(b2 % 2 == 0){
        b2 /= 2;
    }
    while(b2 % 5 == 0){
        b2 /= 5;
    }
    i64 b3 = b / b2;
    std::vector<i64> v;
    for(i64 i = 1; i <= 1e9; i *= 2){
        for(i64 j = i; j <= 1e9; j *= 5){
            if (b2 * j <= 1e9){
                v.push_back(j);
            }
        }
    }
    i64 ans1 = 1e9, ans2 = 1e9;
    for(auto x : v){
        i64 c = a * x % b2;
        c = b2 - c;
        i64 d = x * b2 * b3;
        i64 g = std::gcd(c, d);
        c /= g, d /= g;
        if (c < ans1){
            ans1 = c;
            ans2 = d;
        }
    }
    std::cout << ans1 << " " << ans2 << "\n";

}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    // std::cout << std::fixed << std::setprecision(10); // 固定输出精度
    int t = 1;
    std::cin >> t;

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

    return 0;
}

详细

Test #1:

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

input:

4
1 2
2 3
3 7
19 79

output:

1 2
1 3
1 4375
3 316

result:

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