QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#767686 | #5103. Fair Division | Wsy | WA | 58ms | 3844kb | C++23 | 841b | 2024-11-20 21:44:59 | 2024-11-20 21:44:59 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m;
ll inf=1e18;
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() {
inf+=7;
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 58ms
memory: 3844kb
input:
13 382475111752106101
output:
impossible
result:
wrong answer 1st lines differ - expected: '17 28', found: 'impossible'