您的位置:首页 > 其它

fzu 1050 Number lengths

2017-03-24 17:26 381 查看
Problem Description

N! (N factorial) can be quite irritating and difficult to compute for large values of N. So instead of calculating N!, I want to know how many digits are in it. (Remember that N! = N * (N - 1) * (N - 2) * … * 2 * 1)

Input

Each line of the input will have a single integer N on it 0 < N < 1000000 (1 million). Input is terminated by end of file.

Output

For each value of N, print out how many digits are in N!.

Sample Input

1

3

32000

Sample Output

1

1

130271

求n的阶乘的位数

将1000000个结果都先保存在result[1000000]数组中,根据log10(n*(n-1)(n-2)…*2*1)=log10(n)+log10(n-1)+…+log10(2)+log10(1)的公式,

#include <stdio.h>
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;
const int maxn=1000005;
double a[maxn]= {0};
int main()
{
int n;
while(~scanf("%d",&n))
{
a[0]=1.0;
for(int i=1; i<=10; i++)
{
a[i]=a[i-1]+log10(i*1.0);
}
printf("%d\n",(int)a
);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: