QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#379972 | #5103. Fair Division | cciafrino# | WA | 1ms | 3672kb | C++20 | 1007b | 2024-04-06 20:19:34 | 2024-04-06 20:19:35 |
Judging History
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'