基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题输入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\n");
7 else printf("%d\n",(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('\n');
10 else printf("%I64d\n",(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
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/248892
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!