QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#379982#5103. Fair Divisioncciafrino#WA 1ms3624kbC++201.0kb2024-04-06 20:22:562024-04-06 20:22:57

Judging History

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

  • [2024-04-06 20:22:57]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3624kb
  • [2024-04-06 20:22:56]
  • 提交

answer

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

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

const ll INF = 3e18;

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

__int128_t pw(ull b, ull e) {
    __int128_t 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) {
            __int128_t 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: 3624kb

input:

13 382475111752106101

output:

impossible

result:

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