QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#738490#9622. 有限小数qzhfxWA 0ms3596kbC++232.0kb2024-11-12 19:11:102024-11-12 19:11:10

Judging History

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

  • [2024-11-12 19:11:10]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3596kb
  • [2024-11-12 19:11:10]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 7;
const int mod = 998244353;
const int L = 1e9;
// #define ll __int128
// 求解不定方程 ax+by=c 的最小整数解 x
ll exgcd(ll a, ll b, ll &x, ll &y)
{
    if (!b)
    {
        x = 1;
        y = 0;
        return a;
    }
    ll ans = exgcd(b, a % b, x, y);
    ll tmp = x;
    x = y;
    y = tmp - a / b * y;
    return ans;
}
ll x, y;
ll cal(ll a, ll b, ll c)
{
    x = 0, y = 0;
    ll ans = exgcd(a, b, x, y);
    if (c % ans)
        return -1;
    x *= c / ans;
    b /= ans;
    // y *= c / ans;
    if (b < 0)
        b = -b;
    x = (x % b + b) % b;
    return x;
}
std::vector<ll> px;
void solve()
{
    int a, b;
    cin >> a >> b;
    ll p = b, k = 1;
    while (p % 2 == 0)
    {
        p /= 2;
        k *= 2;
    }
    while (p % 5 == 0)
    {
        p /= 5;
        k *= 5;
    }
    long long c = 1e18, t = 0;
    auto check = [&](ll id)
    {
        c = cal(k, a, p * id);
        // cerr << c << "\n";
        t = (id * p - 1ll * k * c) / a;
        return t >= 1;
    };
    ll d = 1;
    ll cx = 1e18, ct = 0;
    for (auto pd : px)
    {
        ll s = pd / p;
        check(s +k );
        if (c >= 0 && cx > c)
        {
            cx = c;
            d = pd;
        }
    }
    cout << cx << " " << d << '\n';
}
int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    px.push_back(1);
    for (int i = 0;; i++)
    {
        ll now = 1;
        int x = i;
        while (x--)
        {
            now *= 2;
        }
        if (now > L)
            break;
        for (int j = 0;; j++)
        {
            int y = j;
            while (y--)
            {
                now *= 5;
            }
            if (now > L)
                break;
            px.push_back(now);
        }
    }
    int _ = 1;
    cin >> _;
    while (_--)
        solve();
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3596kb

input:

4
1 2
2 3
3 7
19 79

output:

0 1
0 5
0 125
0 256000000

result:

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