Number lengths
Accept: 1100 Submit: 2269
Time Limit: 1000 mSec Memory Limit : 32768 KB
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
13 32000
Sample Output
1 1 130271
题目网址:点击打开链接
题解:就是一道规律题,规律就在代码里。去看看吧!
下面附上代码:
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
#include<string>
#include<vector>
#include<map>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
using namespace std;
int main()
{
int n;
while(~scanf("%d", &n))
{ double ans = 1.0;
for(int i = 1; i <= n; i++)
ans += log10(i*1.0); // 里面要乘一个1.0把int转化为double型,不然会WA
printf("%d\n", (int)ans);
}
}