hdu _p1018 BigNumber

来源:互联网 发布:淘宝实名认证 编辑:程序博客网 时间:2024/06/05 14:32

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;}