#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long lld;
lld gcd(lld a, lld b){
return b == 0? a:gcd(b, a%b);
}
int main(){
lld p, q;
while (scanf("%lld %lld", &p, &q) == 2 &&(p+q)){
if (p == 0){
puts("0 2");
continue;
}
else {
lld i;
lld nu = gcd(p, q);
p/=nu, q/=nu;
for (i = 2; i <= 50000; i++){
if (i * (i - 1) % q == 0){
lld nu = i *(i-1)/q;
lld a = (lld)sqrt(nu * (p));
if (a * (a+1) == nu*p && (a+1 >=2 || (i-a-1 >=2) )){
printf("%lld %lld\n", a+1, i - a - 1);
break;
}
}
}
if (i>50000)puts("impossible");
}
}
return 0;
}
uva 10277 Boastin' Red Socks
最新推荐文章于 2022-05-08 16:37:26 发布