i can't figure the reason for WA...
(got over 15 WAs)
Code: Select all
#include <stdio.h>
#include <math.h>
//void find_base(__int64 worker, int height, __int64 *base, __int64 *expo){
void find_base(long long worker, int height, long long *base, long long *expo){
long long i,j,k = sqrt( worker )+1, x;
//__int64 i,j,k = sqrt( worker )+1, x;
j = (worker&1)?3:2;
for(; j<=k; j += 2){
i = worker;
x = 0;
while( !(i%j) ){
i /= j;
x++;
}
//if( i == 1 && ( (int)pow(j+1,x)==height) ){
//if( i == 1 && ( (__int64)(pow(j+1,x)+0.5)==height) ){
if( i == 1 && ( (long long)(pow(j+1,x)+0.5)==height) ){
*base = j;
*expo = x;
return ;
}
}
*base = worker;
*expo = 1;
}
void main(void){
//freopen("d:\\a\\107.txt","rb",stdin);
//__int64 worker, non_worker, hight, total_hight, base, expo, i,j,k;
long long worker, non_worker, hight, total_hight, base, expo, i,j,k;
//while( 2 == scanf("%I64d %I64d", &hight,&worker) &&(hight ||worker) ){
while( 2 == scanf("%lld %lld", &hight,&worker) &&(hight ||worker) ){
if( worker == 1 ){
//printf("0 %I64d\n\n", hight);
printf("0 %lld\n", hight);
continue;
}
find_base( worker, hight, &base, &expo);
if( expo == 1 ){
//printf("1 %I64d\n\n",hight+worker);
printf("1 %lld\n",hight+worker);
continue;
}
/* hight at a particular level */
k = hight/(base+1);
/* storing base^1 base^0 */
non_worker = base + 1;
total_hight = k*base + hight;
j = base;
for(i = 2; i<expo; i++){
/* all the internal nodes at that hight */
j = j*base ;
k = k/(base+1);
total_hight += j*k;
non_worker += j;
}
total_hight += worker;
//printf("%I64d %I64d\n\n", non_worker, total_hight);
printf("%lld %lld\n", non_worker, total_hight);
}
//return 0;
}
thx...