hdu1018大数

/*
Big Number
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 17223    Accepted Submission(s): 7703


Problem Description
In many applications very large integers numbers are required. Some of these applications are using keys for secure transmission of data, encryption, etc. In this problem you are given a number, you have to determine the number of digits in the factorial of the number.

 

Input
Input consists of several lines of integer numbers. The first line contains an integer n, which is the number of cases to be tested, followed by n lines, one integer 1 ≤ n ≤ 107 on each line.

 

Output
The output contains the number of digits in the factorial of the integers appearing in the input.

 

Sample Input
2
10
20
 

Sample Output
7
19
 

Source
Asia 2002, Dhaka (Bengal) 
 

Recommend
JGShining
*/
#include<iostream>
using namespace std;
int main()
{
    int n,k;
    while(scanf("%d",&n)!=EOF)
    {
        while(n--)
        {
            int num=0;
            double ans=1.0;
            scanf("%d",&k);
            for(int i=1;i<=k;i++)
            {
                ans*=i;
                while(ans/10>=1)
                {
                    ans=ans/10;
                    num++;
                }
            }
            while(ans/10>=1)
            {
                ans=ans/10;
                num++;
            }
            num++;    
            printf("%d\n",num);
        }
    }
    return 0;
}
# include <stdio.h>
# include <math.h>
const double PI=3.1315926;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int sum=1;
        double n;
        scanf("%lf",&n);
        sum+=(int)((0.5*log(2*PI*n)+n*log(n)-n)/log(10.0));
        printf("%d\n",sum);
    }
}
 
/*
ps:简单是简单,可是前提是你必须知道斯特林公式这鬼东西,不然暴力果断会爆掉。

斯特林公式 : n!≈(√(2*π*n))*((n/e)^n)
取以10为底的对数*/

 


posted @ 2012-11-23 20:21  myth_HG  阅读(194)  评论(0编辑  收藏  举报