輸入N求N的階乘的10進制表示的長度。例如6! = 720,長度為3。
求N的階乘長度
計算n!的公式是斯特林公式:
計算一個數的長度為 log10(n) +1
AC代碼:
/**
* ┏┓ ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃ ┃
* ┃ ━ ┃ ++ + + +
* ████━████ ┃+
* ┃ ┃ +
* ┃ ┻ ┃
* ┃ ┃ + +
* ┗━┓ ┏━┛
* ┃ ┃
* ┃ ┃ + + + +
* ┃ ┃
* ┃ ┃ + 神獸保佑
* ┃ ┃ 代碼無bug
* ┃ ┃ +
* ┃ ┗━━━┓ + +
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━┳┓┏┛ + + + +
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛+ + + +
*/
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const double e=2.718281828459;
const double pi=acos(-1.0);
int main()
{
ll n;
while(cin>>n)
{
ll len=0.5*log10(2*n*pi)+n*log10(n/e)+1;
cout<<len<<endl;
}
return 0;
}