2013
11-26

Big Number

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 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.

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

2
10
20

7
19

N！=1*2*3….*n 要求位数我们很自然想到对一个数取对数，log10(n!)=log10(1)+ log10(2) +log10(3)…+log10(n）

#include<stdio.h>
#include<math.h>

int main()
{
int n,i,m;
double sum;
scanf("%d",&n);
while(n--)
{
sum=0;
scanf("%d",&m);
for(i=1;i<=m;i++)
sum+=log10((double)i);
printf("%d\n",(int)sum+1);
}
return 0;
}

#include<stdio.h>
#include<math.h>

#define e 2.7182818284590452354
#define pi acos(-1.00)

int main()
{
int n,i,m,sum;
scanf("%d",&n);
while(n--)
{
scanf("%d",&m);
sum=(int)(1.0/2.0*log10(2.0*pi*m)+1.0*m*log10(m/e)+1);
printf("%d\n",sum);
}
return 0;
}

1. 其实国内大部分公司对算法都不够重视。特别是中小型公司老板根本都不懂技术，也不懂什么是算法，从而也不要求程序员懂什么算法，做程序从来不考虑性能问题，只要页面能显示出来就是好程序，这是国内的现状，很无奈。