QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#742182#9619. 乘积,欧拉函数,求和F0givenersWA 0ms3640kbC++202.2kb2024-11-13 16:02:302024-11-13 16:02:39

Judging History

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

  • [2024-11-13 16:02:39]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3640kb
  • [2024-11-13 16:02:30]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ui = unsigned int;
using ull = unsigned long long;
using ll = long long;
#define endl '\n'
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int maxn = 2e5 + 10;
const int mod = 1000000007;
#define inl inline
#define fr(i, a, b) for (int i = a; i <= b; i++)
#define ford(i, a, b) for (int i = a; i >= b; i--)
#define forall(i, a) for (auto &i : a)

/**
   ____         ___ _____
  / ___| _   _ / _ \___ /
  \___ \| | | | | | ||_ \
   ___) | |_| | |_| |__) |
  |____/ \__, |\___/____/
         |___/
*/
istream &operator>>(istream &in, vector<int> &v)
{
    for (auto &i : v)
        in >> i;
    return in;
}
ostream &operator<<(ostream &out, vector<int> &v)
{
    for (auto &i : v)
        out << i << " ";
    return out;
}
bool _output = 1;

#define int ll

int exgcd(int &x, int &y, int a, int b)
{
    if (b == 0)
    {
        x = 1, y = 0;
        return a;
    }
    int d = exgcd(x, y, b, a % b);
    int z = x;
    x = y;
    y = z - a / b * y;
    return d;
}
void solve()
{
    int a, b;
    cin >> a >> b;
    int p = 1;
    while (b % 2 == 0)
        b /= 2, p *= 2;
    while (b % 5 == 0)
        b /= 5, p *= 5;

    // cout << p << endl;
    if (b == 1)
    {
        cout << "0 1" << endl;
        return;
    }
    // b = b / p;

    int x, y;
    int g = gcd(b, p);

    exgcd(x, y, b, p);
    // bx+py = gcd(b,p) ;
    // cout << gcd(b, p) << endl;
    y = y / gcd(b, p) * a;
    a = y;
    pll ans = {1e18, 1e18};
    for (int t1 = 1; t1 * b <= 1e9; t1 *= 2)
    {
        for (int t2 = 1; t1 * t2 * b <= 1e9; t2 *= 5)
        {

            int q = t1 * t2;
            int c = (((q * a) + b - 1) / b) * b - q * a;
            int d = q * b;
            if (c < ans.first)
            {
                ans = {c, d};
            }
        }
    }
    // cout << (1876 % 7 == 0) << endl;
    cout << ans.first << " " << ans.second << endl;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int _ = 1;
    if (_output)
        cin >> _;
    while (_--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
1 6 8 6 2

output:

1 3
2 3
1 3
1 3
1 3

result:

wrong answer 1st lines differ - expected: '892', found: '1 3'