poj 2661 Factstone Benchmark (Stirling数)

//题意是对于给定的x,求满足n! <= 2^(2^x)的最大的n
//两边同取以二为底的对数,可得: lg2(n!) <= 2^x

 1.
   log2(n!) = log2(1) + log2(2) + .. + log2(n);一个循环即可

 2.
   Stirling

    


#include <iostream> #include <string> #include<sstream> #include <cmath> #include <map> #include <stdio.h> #include <string.h> #include <algorithm> using namespace std; // #define LL __int64 #define LL long long const double pi=acos(-1.0); const double inx_2=log(2.0); // log -> inx log10 int f[30]; int main() { f[0]=1; int i; for(i=1;i<30;i++) f[i]=f[i-1]*2; int year; while(scanf("%d",&year),year) { double t=f[(year-1960)/10+2]; double s=(0.5*log(2*pi)+log(1.0)-1)/inx_2; i=1; while(s<=t) { i++; s=(0.5*log(2*pi*i)+i*log((double)i)-i)/inx_2; } printf("%d ",i-1); } return 0; }
原文地址:https://www.cnblogs.com/372465774y/p/3607310.html