HDU 1018 Big Number
2014-04-06 18:45
423 查看
Big Number
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 24016 Accepted Submission(s): 10884
Problem Description
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
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.
Output
The output contains the number of digits in the factorial of the integers appearing in the input.
Sample Input
2 10 20
Sample Output
7 19
题意:给定一个数n(1<=n<=10^7),求n!的位数。很明显转化为对数就ok了。
注意:一个数x的位数等于用(int)log10(x)+1,所以x=n! 的位数即为log10(x)也就是log10(i) (1<=i<=n)整数部分+1.
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> int gao(int num){ double ans = 0; int i; for(i=2;i<=num;++i){ ans += log10(i*1.0); } return ans; } int main(){ int n,num,res; scanf("%d",&n); while(n--){ scanf("%d",&num); res = gao(num); printf("%d\n",res+1); } return 0; }
相关文章推荐
- HDU 1018 Big Number(杂题)
- HDU 1018 Big Number (数学题)
- HDU 1018 Big Number(斯特林公式)
- HDU 1018 Big Number(斯特林公式)
- HDU1018 Big Number
- hdu 1018 Big Number 数学结论
- HDU 1018-Big Number(数学)
- hdu1018 - Big Number
- hdu 1018 Big Number
- HDU 1018 Big Number(斯特林公式 或 暴力)
- hdu-1018-Big Number
- hdu1018——Big number
- HDU ~ 1018 ~ Big Number (log应用)
- HDU 1018 Big Number 详解
- 【HDU】 1018 Big Number
- hdu_1018_Big Number_求阶乘长度模板题
- Big Number(http://acm.hdu.edu.cn/showproblem.php?pid=1018)
- hdu1018 Big Number 解题报告
- HDU - 1018 - Big Number 【千年老题 - 斯特林公式】
- HDU 1018 Big Number(阶乘位数计算)