hdoj 1018 Big Number (Stirling公式)

http://acm.hdu.edu.cn/showproblem.php?pid=1018
题意:求 N! N ! 有几位
Stirling公式:
log10(n!)=log10(2pin)+nlog10(n/e) l o g 10 ( n ! ) = l o g 10 ( 2 ∗ p i ∗ n ) + n ∗ l o g 10 ( n / e )
所以、、数论题就是会的人秒出,不会的人死都写不出。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
int n,a[1010];
int digit_stirling(int n)
{
    double PI=acos(double(-1));// PI的值=反余弦函数 -1.0为Pi, 1为0。
    double e=exp(double(1));//e的值
    return floor(log10(sqrt(2*PI*n))+n*log10(n/e))+1;//斯特林公式 
}
int main()
{
    int n,T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        printf("%d\n",digit_stirling(n));
    }
    return 0;
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值