QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#742813#9622. 有限小数lzx2017#RE 0ms0kbC++201.5kb2024-11-13 17:23:072024-11-13 17:23:07

Judging History

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

  • [2024-11-13 17:23:07]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-13 17:23:07]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pll pair<int,int>
#define lf float
const int P=998244353;
const int MX=1e12;
int qpow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=ans*a%P;
        a=a*a%P;
        b>>=1;
    }
    return ans;
}
int gcd(int a,int b){
    int t;
    while(b){
        t=b;
        b=a%b;
        a=t;
    }
    return a;
}
int T[50][50]={0};
int K[10000],tk=0;
void solve(){
    int a,b;
    cin>>a>>b;
    int x=b,A=1;
    while(x%2==0)x/=2,A*=2;
    while(x%5==0)x/=5,A*=5;
    if(x==1){
        cout<<0<<' '<<1<<'\n';
        return;
    }
    a%=x;
    vector<pll>ans;
    for(int i=1;i<=tk;i++){
        int c=(x-K[i]*a%x)%x;
        int d=K[i]*x*A;
        ans.push_back({c,d});
    }
    int minc=1e12,mind=1e12;
    for(auto&[c,d]:ans){
        int g=gcd(c,d);
        c/=g,d/=g;
        if(d<=1e9&&c<=minc){
            minc=c;
            mind=d;
        }
    }
    cout<<minc<<" "<<mind<<'\n';
}

signed main(){

    ios::sync_with_stdio(0);
    cin.tie(0);
    T[0][0]=1;
    for(int i=0;i<50;i++){
        for(int j=0;j<50;j++){
            if(T[i][j]>MX)break;
            T[i+1][j]=T[i][j]*2;
            T[i][j+1]=T[i][j]*5;
        }
    }
    for(int i=0;i<50;i++){
        for(int j=0;j<50;j++){
            if(T[i][j]>MX)break;
            if(T[i][j]==0)break;
            K[++tk]=T[i][j];
        }
    }
    int t=1;
    cin>>t;
    while(t--)
    solve();


}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

4
1 2
2 3
3 7
19 79

output:


result: