大一积分赛(二)51Nod - 1058 【数论】

基准时间限制:1 秒 空间限制:131072 KB 分值: 0  难度:基础题
 收藏
 关注
输入N求N的阶乘的10进制表示的长度。例如6! = 720,长度为3。
Input
输入N(1 <= N <= 10^6)
Output
输出N的阶乘的长度
Input示例
6
Output示例
3
相关问题
N的阶乘 mod P 
0
 
N的阶乘 
0
 
N的阶乘的长度
0
 
N的阶乘 V2 
320
N的阶乘的长度 V2(斯特林近似) 
0
考查斯特林公式的应用:
斯特林公式:n!=sqrt(2*pi*n)*(n/e)^n,n!阶乘的长度:len=log(sqrt(2*pi*n)*(n/e)^n)+1


#include<iostream>
#include<algorithm>
#include<cmath>
#define pi acos(-1.0)
#define e 2.718281828459
using namespace std;
typedef long long ll;
int main(){
	ll n;
	while(~scanf("%d",&n)){
		ll ans;
		if(n==1){
			printf("1\n");
		}
		else{
			ans=0.5*log10(2*pi*n)+n*log10(n/e)+1;
			printf("%lld\n",ans);
		}
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/xiang_hehe/article/details/80063012