## Thursday, August 11, 2016

### [SPOJ] FACVSPOW – Factorial vs Power | 书脊

http://www.spoj.com/problems/FACVSPOW/
Consider two integer sequences f(n) = n! and g(n) = an, where n is a positive integer. For any integer a > 1 the second sequence is greater than the first for a finite number of values. But starting from some integer kf(n) is greater thang(n) for all n >= k. You are to find the least positive value of n for which f(n) > g(n), for a given positive integer a > 1.

### Input

The first line of the input contains number t – the amount of tests. Then t test descriptions follow. Each test consist of a single number a.

1 <= t <= 100000
2 <= a <= 106

### Output

For each test print the least positive value of n for which f(n) > g(n).

### Example

```Input:
3
2
3
4

Output:
4
7
9
```

[SPOJ] FACVSPOW – Factorial vs Power | 书脊

https://github.com/ashish1294/BugFreeCodes/blob/master/Spoj/Factorial%20vs%20Power.c
int main()
{
long long int i,a,j;
dpsum[1]=0;
for(i=2;i<3000000;i++)
dpsum[i]=dpsum[i-1]+logl(i);
int t;
scanf("%d",&t);
while(t--)
{
scanf("%lld",&a);
{
j=pow(e,(logl(a)+1));
//printf("Approx =%lld\n",j);
double ss = dpsum[j]/log(a);
while(ss>j)
{
j--;
ss = dpsum[j]/log(a);
}
}
printf("%lld\n",j+1);
}
return 0;
}