QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#767418#5103. Fair DivisionWsyWA 59ms3840kbC++14835b2024-11-20 20:54:012024-11-20 20:54:02

Judging History

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

  • [2024-11-20 20:54:02]
  • 评测
  • 测评结果:WA
  • 用时:59ms
  • 内存:3840kb
  • [2024-11-20 20:54:01]
  • 提交

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'