2010年9月15日 星期三

ACM 107 - The Cat in the Hat

#include <stdio.h>
#include <math.h>
int main()
{
int catH, catWorkCount, sumH;
while (1)
{
int n = 0, p = 0;
scanf("%d %d", &catH, &catWorkCount);
if (catH == 0 || catWorkCount == 0) break;
if (catH == 1 && catWorkCount == 1)
printf("%d %d\n", 0, 1);
else if (catH == 1)
printf("0 %d\n", catWorkCount);
for(n = 2;n <= catH; ++n)
{
int height = catH;
int nowCat = 1;

int totalCat=0;
int notWorkCat=0;

while( (height%n)==0 ){
totalCat += height*nowCat;
notWorkCat += nowCat;

height = height/n;
nowCat = nowCat*(n-1);
}

if(nowCat==catWorkCount){
totalCat += nowCat;
printf("%d %d\n", notWorkCat, totalCat);
break;
}
}
}
return 0;
}


回目錄
回首頁

沒有留言 :

張貼留言

Related Posts Plugin for WordPress, Blogger...