51nod 1130 N的阶乘的长度 V2(斯特林近似)

基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题
 收藏
 关注
输入N求N的阶乘的10进制表示的长度。例如6! = 720,长度为3。
Input
第1行:一个数T,表示后面用作输入测试的数的数量。(1 <= T <= 1000)
第2 - T + 1行:每行1个数N。(1 <= N <= 10^9)
Output
共T行,输出对应的阶乘的长度。
Input示例
3
4
5
6
Output示例
2
3
3

详细解释点击传送门:

斯特林公式

#include <iostream>
#include<math.h>

using namespace std;
typedef long long ll;
/*斯特林公式
sqrt(2*pi*n)*pow(n/e,n)
*/
int main()
{
    ll n;
    ll t;
    cin>>t;
    while(t--)
    {


    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;
}




posted @ 2017-09-22 01:25  Bryce1010  阅读(181)  评论(0编辑  收藏  举报