51Nod1058-N的阶乘的长度

基准时间限制:1 秒 空间限制:131072 KB 分值: 0  难度:基础题
 收藏
 关注
输入N求N的阶乘的10进制表示的长度。例如6! = 720,长度为3。
Input
输入N(1 <= N <= 10^6)
Output
输出N的阶乘的长度
Input示例
6
Output示例
3

利用斯特林近似公式

#include <stdio.h> 
#include <math.h>
#define PI 3.1415925535898
#define e  2.718281828459

int main(){
	long long n;
	scanf( "%lld",&n );
	long long ans = 0.5*log10(2.0*PI*n)+n*log10(1.0*n/e)+1;
	printf( "%lld\n",ans );
}

猜你喜欢

转载自blog.csdn.net/Revenant_Di/article/details/80429080