I tryed long long to hold the numbers, but stil WA.

Here is my code:

Code: Select all

```
#include <stdio.h>
#include <math.h>
#define size_t long
int getl(size_t b, size_t n){
size_t i=n*n;
int count=2;
while( (i<b)&&(i>0) ) {i=i*n; count++;}
if (i==b) return count;
else return 0;
}
int main(){
double nd;
size_t a, b, n, l, sq, idle, height;
while(scanf("%ld%ld", &a, &b)==2){
if (!a && !b) break;
if (a==1 && b==1) printf("0 1\n");
else if (a == b+1) printf("1 %ld", a+b);
else if (b==1){
l = getl(a, 2);
idle = l; height = 2*a-1;
printf("%ld %ld\n", idle, height);
}
else{
sq = (size_t) sqrt(b);
for (n=2; n<=sq; n++)
if (b%n == 0){
l = getl(b, n);
if (l && (fabs(pow(n+1,l) - a) < 0.0001)){
idle = (b-1)/(n-1);
height = b+(a-b)*(n+1);
printf("%ld %ld\n", idle, height);
break;
}
}
}
}
return 0;
}
```

Using geometric progression sums, I've come to the formulas for idle cats and total height.

the if's are for l=0, l=1 respectively n=1, which were special cases for my algorithm.

It works on sample tests and additional tests I've used, and I'm REALLY puzzeled...