QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#790378 | #9622. 有限小数 | Lonelyper | WA | 0ms | 3696kb | C++14 | 1.0kb | 2024-11-28 11:19:05 | 2024-11-28 11:19:06 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define int long long
const int N = 1e18 + 10;
int a, b;
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, y, x);
y -= a / b * x;
return d;
}
int cal(int a, int b, int c){
int x, y;
int d = exgcd(a, b, x, y);
x = x * c / d;
int t = abs(b / d);
return (x % t + t) % t;
}
void WTF()
{
cin >> a >> b;
int w = b;
while(w % 2 == 0) w /= 2;
while(w % 5 == 0) w /= 5;
if(w == 1){
cout << "0 1" << endl;
return;
}
int ansc = 1e18 + 10, ansd = 1e18 + 10;
for(int i = w; i <= N; i *= 2){
for(int d = i; d <= N; d *= 5){
int c = cal(b, - (w * w), - (a * d));
// cout << c << ' ' << d << endl;
// int g = __gcd(c, d);
// if(g != 0) c /= g, d /= g;
if(c < ansc){
ansc = c;
ansd = d;
}
}
}
cout << ansc << ' ' << ansd << endl;
}
signed main()
{
int t = 1;
cin>>t;
while(t --)
{
WTF();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3696kb
input:
4 1 2 2 3 3 7 19 79
output:
0 1 1 3 1 4375 3 1506805419921875
result:
wrong answer Integer 1506805419921875 violates the range [1, 10^9]