QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#788001#9622. 有限小数laonongminWA 0ms3572kbC++201.7kb2024-11-27 15:32:072024-11-27 15:32:21

Judging History

This is the latest submission verdict.

  • [2024-11-27 15:32:21]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3572kb
  • [2024-11-27 15:32:07]
  • Submitted

answer

#pragma GCC optimize(3)
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define N 1000005
#define MOD 998244353
#define INF 1000000000LL
#define IINF 10000000000000000LL
using namespace std;
ll p2[40], p5[40];
void solve()
{
    ll a,b; cin>>a>>b;
    pll ans = {INF,1};
    ll k = b;
    while(k%2==0) k/=2;
    while(k%5==0) k/=5;
    if(k==1) {cout<<"0 1\n"; return;}
    // cout<<k<<'\n';
    for(int x=0;x<=30 && p2[x]*a <= IINF ;++x)
    {
        for(int y=0;p2[x]*p5[y]*a <= IINF && p2[x]*p5[y]*b <= IINF && y<=35;++y)
        {
            // if(x==1 && y==0) {cout<<p2[x]*p5[y]*a<<mx<<'\n';}
            pll now_ans = {k-p2[x]*p5[y]*a%k, p2[x]*p5[y]*b};
            ll d = __gcd(now_ans.first, now_ans.second);
            now_ans.first /= d, now_ans.second /= d;
            if(now_ans.first < ans.first && max(now_ans.first, now_ans.second) < INF) 
            {
                cout<<x<<' '<<y<<'\n';
                ans = now_ans;
            }
            // if(p2[x]*p5[y]*a % k > mx && p2[x]*p5[y]*b <= INF)
            // {
            //     // if(x==1 && y==0) {cout<<"XXX";}
            //     // cout<<x<<' '<<y<<' '<<mx<<'\n';
            //     mx = p2[x]*p5[y]*a % k;
            //     ans = {k-mx, p2[x]*p5[y]*b};
            // }
        }
    }
    ll d = __gcd(ans.first, ans.second);
    ans.first /= d; ans.second /= d;
    cout<<ans.first<<' '<<ans.second<<'\n';
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;
    cin>>T;
    p2[0]=p5[0]=1;
    for(int i=1;i<=35;++i)
    {
        p2[i] = p2[i-1]*2;
        p5[i] = p5[i-1]*5;
    }
    while(T--)
    {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
1 2
2 3
3 7
19 79

output:

0 1
0 0
1 3
0 0
0 2
0 4
1 4375
0 0
0 4
0 5
0 6
0 9
2 0
3 316

result:

wrong answer Integer 0 violates the range [1, 10^9]