QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#744407#9622. 有限小数xiaolei338WA 0ms3504kbC++201.2kb2024-11-13 21:49:432024-11-13 21:49:44

Judging History

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

  • [2024-11-13 21:49:44]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3504kb
  • [2024-11-13 21:49:43]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const int N = 2e5 + 10, mod = 998244353, INF = 0x3f3f3f3f;
random_device rd;
mt19937_64 rng(rd());

LL n, m;
// LL a[N];

LL exgcd(LL a, LL b, LL &x, LL &y) {
    if (!b) {
        x = 1, y = 0;
        return a;
    }
    LL g = exgcd(b, a % b, y, x);
    y -= a / b * x;
    return g;
}

void solve()
{
    LL a, b;
    cin >> a >> b;
    LL t = 1;
    while(b % 2 == 0)
    {
        b /= 2;
        t *= 2;
    }
    while(b % 5 == 0)
    {
        b /= 5;
        t *= 5;
    }
    LL tx, ty;
    exgcd(a, b, tx, ty);
    LL c = b * t - a, d = b * t;
    for(LL p2 = 1; p2 * b <= 1e9; p2 *= 2){
        for(LL p5 = p2; p5 * b <= 1e9; p5 *= 5){
            LL dd = -a * p5;
            LL x = tx * dd;
            x = (x % b + b) % b;
            if(x < c){
                c = x;
                d = b * p5;
            }
        }
    }
    cout << c << ' ' << d << '\n';
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    LL _T = 1;
    cin >> _T;
    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: 3504kb

input:

4
1 2
2 3
3 7
19 79

output:

0 1
1 3
1 875
3 246875000

result:

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