QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#739810#9622. 有限小数MEshooterWA 0ms3644kbC++201.4kb2024-11-12 23:15:352024-11-12 23:15:37

Judging History

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

  • [2024-11-12 23:15:37]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3644kb
  • [2024-11-12 23:15:35]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

using ll = long long;
const int INF = 0x3f3f3f3f;
ll two[100], five[100];
void init(){
    two[0] = five[0] = 1;
    for(int i = 1; i < 32 && two[i-1] < 1e18; i++)
        two[i] = two[i-1]*2;
    for(int i = 1; i < 32 && five[i-1] < 1e18; i++)
        five[i] = five[i-1]*5;
}
ll sub(ll x){
    while(x%2 == 0) x /= 2;
    while(x%5 == 0) x /= 5;
    return x;
}
ll exgcd(ll a, ll b, ll &x, ll &y){
    if(!b){
        x = 1; y = 0;
        return a;
    }
    ll d = exgcd(b, a%b, x, y), t = x;
    x = y;
    y = t-a/b*y;
    return d;
}
int main(){
    ios :: sync_with_stdio(false);
    init();
    int T; cin >> T;
    while(T--){
        ll a, b, w, minc = INF, ans_d, ans_k;
        cin >> a >> b;
        w = sub(b);
        for(int i = 0; i < 32 && w*two[i] <= 1e9; i++){
            for(int j = 0; j < 32 && w*two[i]*five[j] <= 1e9; j++){
                // w^2 * k - b * c = a*d;
                ll d = w*two[i]*five[j], k, c;
                exgcd(w*w, b, k, c);
                ll t = max(-(a*d*k)/b+1, a*d*c/(w*w)+1);
                c = -a*d*c/w+w*t;
                k = a*d*k/w+b*t/w;
                // cout << c << " " << t << endl;
                if(c < minc) minc = c, ans_d = d, ans_k = k;
            }
        }
        cout << minc << " " << ans_d << endl;
    }
    return 0;
}

详细

Test #1:

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

input:

4
1 2
2 3
3 7
19 79

output:

1 1
1 3
1 4375
3 316

result:

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