QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#742942#9622. 有限小数QOJericWA 0ms3648kbC++171.1kb2024-11-13 17:42:362024-11-13 17:42:44

Judging History

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

  • [2024-11-13 17:42:44]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3648kb
  • [2024-11-13 17:42:36]
  • 提交

answer

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

using namespace std;
int n;
vector<int>i2j5;
void init(){
    for(ll i=1;i<=1e9;i*=2){
        for(ll j=i;j<=1e9;j*=5){
            i2j5.push_back(j);
        }
    }
    sort(i2j5.begin(),i2j5.end());
    cerr<<i2j5.size()<<endl;
}
void f(ll b,ll &_b,ll &fb){
    _b=1;
    while(b%2==0){
        b/=2;
        _b*=2;
    }
    while(b%5==0){
        b/=5;
        _b*=5;
    }
    fb = b;
}

int main(){
    //cout<<(int)5e9<<endl;
    init();
    int _;cin>>_;
    while(_--){
        ll a,b,_b,fb;//fb*_b=b
        ll c=b-a,d=b;
        cin >> a >>b;
        f(b,_b,fb);

        if(fb==1){
            cout<<"0 1\n";
            continue;
        }

        for(ll i:i2j5){
            ll ai=a*i;
            ll cur =(ai/fb+1)*fb;//cur=p*fb
            while((cur-ai)%_b){
                cur+=fb;
            }
            ll cur_c = (cur-ai)/_b;
            if (cur_c<c){
                c= cur_c;
                d=fb*i;
            }
        }

        cout<<c<<" "<<d<<'\n';

    }
}

详细

Test #1:

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

input:

4
1 2
2 3
3 7
19 79

output:

0 1
1 2
1 3
3 316

result:

wrong answer The result is not terminating.(Testcase 2)