51nod 1130

来源:互联网 发布:mac百度云下载没反应 编辑:程序博客网 时间:2024/05/22 15:57

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 <string>#include <cstring>#include <stdio.h>#include <cmath>using namespace std;#define PI acos(0.0)#define E  exp( 1.0 )int main(){    int n;    cin>>n;    while(n--)    {        long long  t;        cin>>t;        long long y;        y=log10(sqrt(4.0*PI*t))+(log10(t)-log10(E))*t+1.0;        if(t==1) y++;        cout<<y<<endl;    }    return 0;}
0 0
原创粉丝点击