杭电上面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;
}

 

相关文章:

  • 2021-06-08
  • 2021-06-02
  • 2022-02-11
  • 2021-11-03
  • 2022-12-23
  • 2018-02-07
  • 2021-07-28
  • 2022-12-23
猜你喜欢
  • 2021-12-26
  • 2022-12-23
  • 2022-12-23
  • 2021-05-10
相关资源
相似解决方案