您的位置:首页 > 其它

hdu _p1018 BigNumber

2013-11-22 15:39 225 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1018

分析: stirling数的应用

             stirling公式:

           

            Len=  log10  (n!)  +1;

       注意: 因为math.h中的log是以自然对数为底的所以应该换底,同时注意利用对数对公式的化简。

代码:

      //hdu 1018 Big Number(n! digits stirling)
#include <stdio.h>
#include <math.h>
#include <iostream>
#define pai acos(-1.0)
using namespace std;

int main()
{
int t,n;
int len;
double tmp;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
tmp=0.5*log(2*pai*n) + n*log(n*1.0) - n;
len=(int)(tmp/log(10.0))+1;
printf("%d\n",len);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  hduacm 初等数论