QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#737731#9622. 有限小数WilliamtymWA 1ms3636kbC++201.5kb2024-11-12 16:44:262024-11-12 16:44:32

Judging History

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

  • [2024-11-12 16:44:32]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3636kb
  • [2024-11-12 16:44:26]
  • 提交

answer

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>

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

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();
    LL x, y;
    LL t = 1;
    while(b % 2 == 0)
    {
        b /= 2;
        t *= 2;
    }
    while(b % 5 == 0)
    {
        b /= 5;
        t *= 5;
    }

    LL d = exgcd(t, b, x, y);
    LL u = b * t - a;
    LL v = b * t;
    for(LL i = 1;i * b <= 1e9; i *= 2)
    {
        for(LL j = 1;j * b <= 1e9; j *= 5)
        {
            LL l = x * (-a * j);
            l = (l % b + b) % b;

            if(l < u)
            {
                u = l;
                v = j * b;
            }
        }
    }
    write(u), putchar(' '), write(v), putchar('\n');
}

int main()
{
    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: 1ms
memory: 3636kb

input:

4
1 2
2 3
3 7
19 79

output:

0 1
1 3
1 4375
6 154296875

result:

wrong answer Jury found better answer than participant's 3 < 6 (Testcase 4)