N的阶乘的长度

输入N求N的阶乘的10进制表示的长度。例如6! = 720,长度为3。
 
Input
输入N(1 <= N <= 10^6)
Output
输出N的阶乘的长度
Input示例
6
Output示例
3
李陶冶 (题目提供者)
 
C++的运行时限为:1000 ms ,空间限制为:131072 KB
 
有一个叫斯特林近似公式的东西。
代码实现:
1 #include<cmath>
2 #include<cstdio>
3 int n,res;
4 int main(){
5     scanf("%d",&n);
6     if(n==1) printf("1
");
7     else printf("%d
",(long)((log10(sqrt(4.0*acos(0.0)*n))+n*(log10(n)-log10(exp(1.0))))+1));
8     return 0;
9 }
 1 #include<cmath>
 2 #include<cstdio>
 3 #define LL long long
 4 LL t,n;
 5 int main(){
 6     scanf("%I64d",&t);
 7     while(t--){
 8         scanf("%I64d",&n);
 9         if(n==1) putchar('1'),putchar('
');
10         else printf("%I64d
",(LL)((log10(sqrt(4.0*acos(0.0)*n))+n*(log10(n)-log10(exp(1.0))))+1));
11     }
12     return 0;
13 }

题目来源:51Nod

原文地址:https://www.cnblogs.com/J-william/p/6375915.html