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)的公式,
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; }
相关文章推荐
- FZU 1050 Number lengths (思维题)
- fzu 1050 Number lengths
- FZU1050 Number lengths(数论,规律,概念)
- 省赛选拔赛之个人赛(三)FZU 1026 |1050 +HDU 3466【思路题】
- Number lengths FZU - 1050
- FZU Number lengths(数学)
- FZU Number lengths(数学)
- FZU Number lengths(数学)
- FZU Number lengths(数学)
- FZU Number lengths(数学)
- FZU Number lengths(数学)
- FZU Number lengths(数学)
- FZU Number lengths(数学)
- FZU Number lengths(数学)
- FZU Number lengths(数学)
- FZU Number lengths(数学)
- FZU Number lengths(数学)
- FZU Number lengths(数学)
- FZU Number lengths(数学)
- FZU2104之Floor problem