数学知识(求阶乘的位数) HDU 1018

   big number

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.
 

 

可以将n!表示成10的次幂,即n!=10^M(10的M次方,10^2是3位M+1就代表位数)则不小于M的最小整数就是
    n!的位数,对该式两边取对数,有M=log10^n!(以10为底的n!的对数值)即:
    M = log10^1+log10^2+log10^3...+log10^n
    循环求和,就能算得M值,该M是n!的精确位数。

#include<iostream>
#include<cmath>
using namespace std;

int doProcess(int n)
{
	float i,sum=1;
	for(i=1;i<=n;i++)
		sum+=log10(i);   //以10为底的对数的值   log10(i)的原型: float log10(float i);
	return (int)sum;
}

int main()
{
	int caseNum,i,n;
	while(cin>>caseNum)
	{
		for(i=0;i<caseNum;i++)
		{
			cin>>n;
			cout<<doProcess(n)<<endl;			
		}
	}
	return 0;
}
 

 运行出了结果,但不知道为什么就wrong Answer  了,很是郁闷啊



posted @ 2014-11-07 08:52  zhoudan  阅读(164)  评论(0)    收藏  举报