斯特林公式 hdu1018

杭电上面1018》》点击测试《《

 

思路:当问到阶乘的值时候,用万进制来写;但是问阶乘值的位数的时候,就可以用斯特林公式了

log10(2*pi*n)/2+n*log10(n/e)+1

注意cmath中log()和log10()的使用;

#include<cstdio>
#include<cmath>
#include<iostream>
using namespace std;
#define PI 3.14159265
int main()
{
    int t; cin >> t;
    while (t--){
        double n; cin >> n;
        int flag = 0.5*log10(2 * PI*n) + n*(log(n) - 1) / log(10) + 1;
        cout << flag << endl;
    }
    return 0;
}

 

posted @ 2018-04-13 15:02  我只有一件白T恤  阅读(128)  评论(0编辑  收藏  举报