QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#379972#5103. Fair Divisioncciafrino#WA 1ms3672kbC++201007b2024-04-06 20:19:342024-04-06 20:19:35

Judging History

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

  • [2024-04-06 20:19:35]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3672kb
  • [2024-04-06 20:19:34]
  • 提交

answer

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

using ll = long long;
using ull = unsigned long long;

const ll INF = 3e18;

ll mul(ll a, ll b) {
    ll ret = a * b;
    return min(ret, INF);
}

ll pw(ull b, ull e) {
    ll ans = 1;
    for (; e; b = mul(b, b), e /= 2) {
        if (e & 1) ans = mul(ans, b);
    }
    return ans;
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int N; ll M; cin >> N >> M;

    pair<ll, ll> ans;
    bool found = false;
    for (int q = 2; pw(q, N) <= M; ++q) {
        if (found) break;
        for (int p = 1; p < q; ++p) {
            ll S = 0;
            for (int i = 0; i < N; ++i) {
                S += mul(pw(q, i), pw(p, N-1-i));
                if (S > INF) S = INF;
            }
            if (M % S == 0) {
                ans = {q-p, q};
                found = true;
            }
        }
    }

    if (found) cout << ans.first << ' ' << ans.second << '\n';
    else cout << "impossible\n";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3672kb

input:

13 382475111752106101

output:

impossible

result:

wrong answer 1st lines differ - expected: '17 28', found: 'impossible'