Number lengths FZU - 1050
2017-03-23 23:03
190 查看
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
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!位数应该是 log10(1)+log10(2)+···+log10(n) 取整加1, //注意:log10(n)传入的值必须是double型,所以要进行强制转换! #include<map> #include<queue> #include<stack> #include<vector> #include<math.h> #include<cstdio> #include<sstream> #include<numeric>//STL数值算法头文件 #include<stdlib.h> #include<string.h> #include<iostream> #include<algorithm> #include<functional>//模板类头文件 using namespace std; const int INF=1e9+7; const int maxn=110; typedef long long ll; int n; int main() { while(~scanf("%d",&n)) { int i,j=0; double sum=0; for(i=1; i<=n; i++) sum+=log10(double(i)); j=(int)sum+1; printf("%d\n",j); } return 0; }
相关文章推荐
- fzu Problem 1649 Prime number or not
- FZU1050 Number lengths(数论,规律,概念)
- fzu 1050 Number lengths
- FZU 1649 Prime number or not (米勒拉宾大素数判断+快速幂取模+随机数模板)
- FZU 2111Min Number
- FZU 1649 Prime number or not (Miller-Rabin素数测试)
- FZU——2111Min Number(多次交换得到最小数,水题)
- 数学 FZU 2074 Number of methods
- fzu 1050 Number lengths
- FZU-2231-平行四边形数 cf-Number of Parallelograms
- FZU 1649 Prime number or not (Miller-Rabin素数测试)
- fzu 2111 Min Number 贪心
- 省赛选拔赛之个人赛(三)FZU 1026 |1050 +HDU 3466【思路题】
- J - Min Number FZU - 2111——桶思想深化
- Leetcode:Missing Number & Maximum Product of Word Lengths
- FZU 1649 Prime number or not (大素数判定)
- hdu 2462 poj 3696 The Luckiest number fzu 1017 zoj 1537 Playing with Calculator
- FZU 1050 Number lengths (思维题)
- yii CListView - adding serial number 添加序号
- iOS为你的数字添加动画:AMAnimatedNumber控件