poj2661Factstone Benchmark
利用log函数来求解 n!<=2^k k会达到400+W 暴力就不要想了,不过可以利用log函数来做
log2(n!) = log2(1)+log2(2)+..log2(n)<=k
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<stdlib.h> 6 #include<vector> 7 #include<cmath> 8 #include<queue> 9 #include<set> 10 #include<map> 11 using namespace std; 12 #define N 100000 13 #define LL long long 14 #define INF 0xfffffff 15 const double eps = 1e-8; 16 const double pi = acos(-1.0); 17 const double inf = ~0u>>2; 18 int main() 19 { 20 int i,j,n; 21 //cout<<log10(10)<<" "<<log(10)<<endl; 22 while(cin>>n) 23 { 24 if(!n) break; 25 LL k = 2; 26 for(i = 1960 ; i <= n ; i+=10) 27 k*=2; 28 double d=0; 29 int ans; 30 for(i = 1; ; i++) 31 { 32 d+=log10(i*1.0)/log10(2.0); 33 if(d>k) 34 { 35 ans = i-1; 36 break; 37 } 38 } 39 cout<<ans<<endl; 40 } 41 return 0; 42 }