斯特林公式求解n!位数

OJ题目:http://www.51nod.com/Challenge/Problem.html#!#problemId=1130

 斯特林公式n!=sqrt(2*PI*n)*(n/e)^n

#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;

int main()
{
	int N;
	cin>>N;
	while(N--)
	{
		long long n;
		cin>>n;
		double len=0;
		long long ans=0;
		len=0.5*log10(2*3.1415927*n)+n*log10(n/2.718281828459); 
		ans=(long long)len+1;
		cout<<ans<<endl;

	}
	return 0;
} 

 

全部评论

相关推荐

06-17 21:57
门头沟学院 Java
白友:噗嗤,我发现有些人事就爱发这些,明明已读不回就行了,就是要恶心人
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务