QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#767418 | #5103. Fair Division | Wsy | WA | 59ms | 3840kb | C++14 | 835b | 2024-11-20 20:54:01 | 2024-11-20 20:54:02 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m;
ll inf=1e18+7;
ll mul(ll x,ll y) {
__int128 t=(__int128)(x) * y;
if (t>=(__int128)(inf)) return inf;
return ll(t);
}
ll fastpow(ll x,int b) {
ll ret=1;
while (b) {
if (b&1) ret=mul(ret,x);
if (ret==inf) return inf;
b>>=1;
x=mul(x,x);
if (x==inf) return inf;
}
return ret;
}
bool check(int p,int q) {
ll ans=0;
for (int i=0;i<=n-1;i++) {
ll tmp=mul(fastpow(q,i),fastpow(q-p,n-i-1));
if (tmp==inf) return false;
ans+=tmp;
if (ans>=inf) return false;
}
return (m%ans==0);
}
int main() {
scanf("%lld%lld",&n,&m);
for (int q=1;q<=4000;q++)
for (int p=1;p<q;p++) {
if (check(p,q)) {
printf("%lld %lld",p,q);
return 0;
}
}
printf("impossible\n");
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 59ms
memory: 3840kb
input:
13 382475111752106101
output:
impossible
result:
wrong answer 1st lines differ - expected: '17 28', found: 'impossible'