uva107 The Cat in the Hat
以下代码,纯属抄袭。如有雷同,实属必然。
View Code
1 #include<stdio.h> 2 #include<math.h> 3 #include<string.h> 4 int main() 5 { 6 int h, n, k, N, a, b, i; 7 while(scanf("%d%d",&h,&n) && (h || n)) 8 { 9 if(h == 1 && n == 1) 10 { 11 puts("0 1"); 12 continue; 13 } 14 N = a = k = 1; 15 b = h+n; 16 for(k = 1;h != int(pow(1.0+pow(n,1.0/k),k)+0.1); k++); 17 N = int(pow(n,1.0/k)+0.1); 18 for(i = 1;i < k; i++) 19 { 20 a += int(pow(double(N),double(i))); 21 b += int(pow(double(N),double(i))/pow(double(N+1),double(i))*h+0.1); 22 } 23 printf("%d %d\n",a,b); 24 } 25 return 0; 26 }