QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#738094 | #9622. 有限小数 | Williamtym | WA | 0ms | 3580kb | C++20 | 1.6kb | 2024-11-12 17:42:26 | 2024-11-12 17:42:29 |
Judging History
answer
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;
LL read()
{
LL x = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9')
{
if(ch == '-') f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9')
{
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
void write(LL x)
{
if(x < 0)
{
putchar('-');
x = -x;
}
if(x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
set<LL> s;
void init()
{
for(int i = 1;i <= 1e7; i *= 2)
for(int j = i;j <= 1e7; j *= 5)
s.insert(j);
}
LL exgcd(LL a, LL b, LL &x, LL &y)
{
if(!b)
{
x = 1, y = 0;
return a;
}
LL d = exgcd(b, a % b, x, y);
LL t = x;
x = y;
y = t - a / b * x;
return d;
}
void solve()
{
LL a = read(), b = read();
if(s.count(b))
{
cout << 0 << ' ' << 1 << endl;
return;
}
while(b % 2 == 0)
b /= 2;
while(b % 5 == 0)
b /= 5;
LL minv = 1e9;
LL u, v;
for(auto i : s)
{
u = (b - a * i % b) % b;
if(minv > u)
{
minv = u;
v = b * i;
cout << minv << endl;
}
}
cout << minv / __gcd(minv, v) << ' ' << v / __gcd(minv, v) << endl;
}
int main()
{
init();
LL T = read();
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: 3580kb
input:
4 1 2 2 3 3 7 19 79
output:
0 1 1 1 3 4 1 1 14 60 41 3 3 316
result:
wrong answer The result is not terminating.(Testcase 2)