标签:
这道题列出不等式后明显是会溢出的大数,但是没有必要写高精度,直接两边取对数(这是很简明实用的处理技巧)得:
log2(n!)=log2(n)+log2(n-1)+...+log2(1)<=log2(2k-1)<k
其中k是第y年计算机的位数。
注意C++中log(n)是以e为底的对数,log10(n)是以10为底的对数,若要计算loga(b),用换底公式loga(b)=logx(b)/logx(a)即可。
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<string> #include<cmath> #include<map> #include<set> #include<list> #include<deque> #include<vector> #include<algorithm> #include<stack> #include<queue> #include<cctype> #include<sstream> using namespace std; #define pii pair<int,int> #define LL long long int const double eps=1e-10; const int INF=1000000000; const int maxn=0; int n; int main() { //freopen("in2.txt","r",stdin); //freopen("out.txt","w",stdout); while(scanf("%d",&n)==1&&n) { int t=(n-1960)/10+2; int k=(1<<t); //cout<<k<<endl; double i=1; double r=0; for(;r<(double)k;i++) { //cout<<‘i‘<<‘ ‘<<i<<endl; //cout<<log(i)/log(2)<<endl; r+=log(i)/log(2.0); //cout<<r<<endl; } cout<<i-2<<endl; } //fclose(stdin); //fclose(stdout); return 0; }
poj2661 Factstone Benchmark(大数不等式同取对数ji)
标签:
原文地址:http://www.cnblogs.com/zywscq/p/4415639.html