QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#738094#9622. 有限小数WilliamtymWA 0ms3580kbC++201.6kb2024-11-12 17:42:262024-11-12 17:42:29

Judging History

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

  • [2024-11-12 17:42:29]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3580kb
  • [2024-11-12 17:42:26]
  • 提交

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;
}

详细

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)