基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题
输入N求N的阶乘的10进制表示的长度。例如6! = 720,长度为3。
Input
输入N(1 <= N <= 10^6)
Output
输出N的阶乘的长度
Input示例
6
Output示例
3
斯特林公式:
斯特林公式可以用来估算某数的大小,结合lg可以估算某数的位数,或者可以估算某数的阶乘是另一个数的倍数。
Stirling公式:sqrt(2*pi*n)*pow(n/e,n)
Stirling公式求阶乘位数:log10(sqrt(2*M_PI*n))+n*log10(n/M_E) 注意强制类型转换成double型
#include <iostream>
#include<math.h>
using namespace std;
typedef long long ll;
/*斯特林公式
sqrt(2*pi*n)*pow(n/e,n)
*/
int main()
{
ll n;
cin>>n;
//对斯特林公式开log求阶乘位数
ll l=log10((long double)(sqrt(2*M_PI*n)))+n*log10((long double)n/M_E)+1;
cout<<l<<endl;
return 0;
}