//求N!的位数
//N!=1*2*3*
*N,两边取常用对数,即可算出log10(N!),向上取整即为N!的位数
//hdoj 984MS 344K
//N!=1*2*3*
![](http://www.cppblog.com/Images/dot.gif)
//hdoj 984MS 344K
#include <iostream> #include <cmath> using namespace std; int main() { double sum=0.0; int n,i,times,res; if(cin>>times&×!=0) { while(times) { cin>>n; for(i=2;i<=n;++i) sum+=log10(i); res=ceil(sum); cout<<res<<endl; sum=0.0; --times; } } return 0; } //String公式的方法,N!~sqrt(2*pi*N)*(N/e)^N //hdoj 0MS 360K #include <iostream> #include <cmath> using namespace std; const double pi=3.1415926; int main() { int n,times; long double sum; if(cin>>times&×) { while(times) { cin>>n; sum=(long double)0.5*log10(2*pi*n)+(long double)n*(log10(n)-log10(exp(1))); cout<<(long)ceil(sum)<<endl; --times; } } return 0; }