QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#743119#9622. 有限小数yzhx#WA 0ms3680kbC++111.1kb2024-11-13 18:18:352024-11-13 18:18:36

Judging History

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

  • [2024-11-13 18:18:36]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3680kb
  • [2024-11-13 18:18:35]
  • 提交

answer

#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
#define int ll
vector<ll> k;
inline int exgcd(int a,int b,int &x,int &y)
{
    if(b==0) {x=1,y=0; return a;}
    int d=exgcd(b,a%b,x,y);
    int z=x;
    x=y, y=z-y*(a/b);
    return d;
}
void slove(){
    ll up = 1e9;
    ll a, b;
    cin >> a >> b;
    int bb=b;
    while(bb % 2 == 0) bb /= 2;
    while(bb % 5 == 0) bb /= 5;
    int k1=b/bb;
    if (bb == 1) {
        cout << "0 1\n";
        return ;
    }
    int C=1e18,D=0;
    for (int i = 0 ; i < k.size() ; i++){
        int k2=k[i];
        int t=(-(a*k2)%bb+bb)%bb;
        int x, y;
        int gcd=exgcd(k1,bb,x,y);
        int lcm=bb/gcd;
        int c=x%lcm;
        if(c<C) {C=c, D=bb*k2;}
    }
    cout<<C<<' '<<D<<endl;
}

signed main(){
   ll up = 1e9;

   for (ll i = 1 ; i <= (ll)1e9 ; i *= 2LL){
       ll tmp = i;
       while(tmp <= up){
          k.push_back(tmp);
          tmp *= 5LL;
       }
   }

//    cout << k.size() << endl;
   int cnt = 1;
   cin >> cnt;

   while(cnt--) {
    slove();
   }

   return 0;
}
/*
4
1 2
2 3
3 7
19 79
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
1 2
2 3
3 7
19 79

output:

0 1
1 3
1 7
1 79

result:

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