My code gives TLE. What further optimization is required in my code??
https://www.spoj.pl/problems/FACVSPOW/

/*FACVSPOW*/
#include<stdio.h>
#include<cmath>

using namespace std;

int calc(long n, long a)
{
 if(((n*log(n)-n)+0.5*log(2*M_PI*n)-n*log(a))>=0)
 return 1;
 else return -1;
}
int main()
{
long t;
scanf("%ld",&t);
long a;
while(t--)
{
 scanf("%ld",&a);
 long lo=2*a;
 long hi=(long)(2.718281828*a) + 1;
 long mid;
 while(lo<hi)
 {
  mid=(lo+hi)/2;
  if(calc(mid,a)<0)
  lo=mid+1
  else if(calc(mid,a)>0)
  hi=mid;

  if(calc(mid,a)>0 && calc(mid-1,a)<0)
  break;
 }
  printf("%ld\n",mid);
}
return 0;
}

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to