
I hope you will be able to find some solution -- I'd very much like to see it. I never turn down any possible good approach.

Best regards
Ivor
Moderator: Board moderators
Code: Select all
#include <stdio.h>
#include <math.h>
void main()
{
long n,n2,m,level,a,flag;
double temp,height_of_stack,num_of_worker;
double height_of_first,non_working;
float rev,n1;
for(;;)
{
scanf("%lf %lf",&height_of_first,&num_of_worker);
if(height_of_first==0 && num_of_worker==0)
break;
if((height_of_first-num_of_worker)==1.0)
printf("%ld %.0lf\n",1,(height_of_first+num_of_worker));
else
{
flag=1;
for(m=2;m<=31;m++)
{
rev=1.0/m;
n1=pow(num_of_worker,rev);
n2=(long)n1;
if((n1-n2)<1.0)
{
if(height_of_first==pow((double)(n2+1),m))
{
n=n2;
level=m;
flag=0;
}
}
if(!flag) break;
}
temp=n-1;
non_working=(num_of_worker-1)/temp;
height_of_stack=0;
for((a=0,m=level);a<=level;(a++,m--))
height_of_stack+=(pow((double)n,a)*pow((double)(n+1),m));
printf("%.0lf %.0lf\n",non_working,height_of_stack);
}
}
}