QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#737562#9622. 有限小数nekohshizukuWA 6ms67788kbC++203.0kb2024-11-12 16:13:442024-11-12 16:13:45

Judging History

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

  • [2024-11-12 16:13:45]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:67788kb
  • [2024-11-12 16:13:44]
  • 提交

answer

#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<stack>
#include<unordered_map>
#include<map>
#include<set>
#include<cstring>
#include<vector>
#include<numeric>
#include<queue>
#define Arr arr
#define null NULL
#define Endl endl
#define db double
#define pll pair<ll,ll>
#define vpll vector<pair<ll,ll> >
#define vll vector<ll>
#define vvpll vector<vector<pair<ll,ll> > >
#define vvll vector<vector<ll> >
#define privll priority_queue<ll, vector<ll> ,greater<ll> >
#define privpll priority_queue<pair<ll, ll>, vector<pair<ll,ll> > ,greater<pair<ll,ll> > >
#define ll long long
#define amonglr(x,l,r) x >= l && x <= r
#define rep(i,s,n) for(ll i = (s);i <= (n);i++)
#define per(i,s,n) for(ll i = (s);i >= (n);i--)
using namespace std;

const ll N = 2e6 + 10;
ll mod = 1e9 + 7, inf = 1e17;
string str, stt, stl[N];
ll m, t, k, n, num[N], arr[N];

ll qpow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

ll gcd(ll a, ll b) {
    return !b ? a : gcd(b, a % b);
}

void exgcd(int a, int b,ll &x,ll &y)
{
    if (b == 0)
    {
        x = 1, y = 0;
        return;
    }
    exgcd(b, a % b, y, x);
    y -= (a / b) * x;
}

void solve() {
    ll a, b;
    cin >> a >> b;
    ll temp = b, ans = 1e12, ans1 = 1e12, cnt2{}, cnt5{};
    while (temp % 2 == 0) {
        temp /= 2;
        cnt2++;
    }
    while (temp % 5 == 0) {
        temp /= 5;
        cnt5++;
    }
    if (temp == 1) {
        cout << 0 << " " << 1 << Endl;
        return;
    }
    ll q1 = 1, q2 = 1;
    for (int i = 0;; i++) {
        ll d = q1 * temp;
        q1 *= 2;
        if (i > cnt2) q2 = q2 * 2;
        ll q5 = 1;
        if (d > 1e9) break;
        for (int j = 0;; j++) {
            if (j) d *= 5;
            if (j > cnt5)  q5 *= 5;
            if (d > 1e9) break;
            ll aa = a * q2 * q5;
            ll res = aa / temp * temp + temp - aa;
            ll res1 = 1;
            if (q2 == 1) {
                res1 = res1 * qpow(2, cnt2 - i);
            }
            if (q5 == 1) {
                res1 = res * qpow(5, cnt5 - j);
            }
            if (res1 == 1) {
                if (ans > res) {
                    ans = res;
                    ans1 = d;
                }
            }
            else {
                ll temp1 = res;
                temp1 %= res1;
                temp1 = res1 - temp1;
                ll x, y;
                exgcd(temp, res1, x, y);
                k = (x % res1 + res1) % res1 * temp1 % res1;
                res = (res + k * temp) / res1;
                if (ans > res) {
                    ans = res;
                    ans1 = d;
                }
            }
        }
    }
    cout << ans << " " << ans1 << endl;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    t = 1;
    cin >> t;
    while (t--) solve();
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 6ms
memory: 67788kb

input:

4
1 2
2 3
3 7
19 79

output:

0 1
1 3
1 7
1 79

result:

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