## Getting TLE again and again

Moderator: Board moderators

assasin
New poster
Posts: 7
Joined: Wed Feb 13, 2008 3:59 pm

### Getting TLE again and again

I could not figure out why my code is getting TLE?
Plese someone help me to find it out and give me some input so that my code runs infinitely

Here is my code:

Code: Select all

``````#include <stdio.h>
#include <math.h>

#define epsilon 0.0000001

int main(){

double root,leaf;
double lazy,height;
double level,branch;
bool ok = false;

while(scanf("%lf%lf",&root,&leaf) ){

if(root == 0 && leaf == 0)
break;

if(root == 1 && leaf == 1){
printf("0 1\n");
}

else if(leaf == 1){

double k = log(root)/log(2);
double Sheight = pow(2,k+1)-1;

printf("%.0lf %.0lf\n",k,Sheight);

}

else{

ok = false;
//finding branch
branch = 2.0;
while(!ok){

double temp1,temp2;

temp1 = log(root)/log(leaf);
temp2 = log(branch+1.0)/log(branch);

if(fabs(temp1 - temp2) <= epsilon)
ok = true;
else branch+=1.0;
}

level = log(leaf) / log(branch);

lazy = ( pow(branch,level) - 1 ) / (branch - 1);

double loop = 1.00;
height = root;

while(1){

height = height +  ( root / pow(branch+1,loop) ) * pow(branch,loop);
if( fabs(loop - level) <= epsilon )
break;
else loop += 1.0;
}

printf("%.0lf %.0lf\n",lazy,height);
}
}

return 0;
}
``````
Thanks

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm