QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#379982 | #5103. Fair Division | cciafrino# | WA | 1ms | 3624kb | C++20 | 1.0kb | 2024-04-06 20:22:56 | 2024-04-06 20:22:57 |
Judging History
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";
}
詳細信息
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'