QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#737514#9630. 沙堆rikka_lyly#WA 0ms3652kbC++201.5kb2024-11-12 16:02:262024-11-12 16:02:26

Judging History

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

  • [2024-11-12 16:02:26]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3652kb
  • [2024-11-12 16:02:26]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define int ll
#define INF 0x3f3f3f3f3f3f3f3f
#define MAXD 1000000000

ll inv(ll x, ll p);

ll qpow(ll a, ll b, ll p = 1e18 + 7)//默认情况下认为到不了这么大
{
    if(b < 0)
        return inv(qpow(a, -b, p), p);
    ll ans = 1;
    while (b)
    {
        if(b & 1)
            ans = ans * a % p;
        a = a * a % p;
        b >>= 1;
    }
    return ans;
}
ll inv(ll x, ll p)
{
    return qpow(x, p - 2, p);
}

void solve()
{
    ll a, b;
    cin >> a >> b;
    ll x = b, p1 = 0, q1 = 0;
    while (x % 2 == 0)
    {
        x /= 2;
        p1++;
    }
    while (x % 5 == 0)
    {
        x /= 5;
        q1++;
    }
    if(x == 1)
    {
        cout << 0 << " " << 1 << '\n';
        return;
    }
    pair<int, int> ans = {INF, INF};
    for (int p2 = 0; ; p2++)
    {
        int tp = x * qpow(2, p2);
        if(tp > MAXD)
            break;
        for (int q2 = 0; ; q2++)
        {
            ll d = x * qpow(2, p2) * qpow(5, q2);
            if(d > MAXD)
                break;
            ll c = (x - a * qpow(2, p2 - p1, x) % x * qpow(5, q2 - q1, x) % x) % x;
            ans = min(ans, {c, d});
        }
    }
    cout << ans.first << " " << ans.second << '\n';
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6
1 2
2 3
2 4
1 5
4 6
1 1 0 0 1 1

output:

0 1
1 3
0 1
0 1
1 3
0 1

result:

wrong answer 1st lines differ - expected: '1 2 0 1 0 0', found: '0 1'