HDU 1018--关于阶乘大数问题
2012-01-24 19:30
225 查看
题目:
[b] Big Number[/b]
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 13404 Accepted Submission(s): 5967
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
Source
Asia 2002, Dhaka (Bengal)
Recommend
JGShining
分析:
第一种方法:
N!=1*2*3....*n 要
求位数我们很自然想到对一个数取对数,
log10(n!)=log10(1)+ log10(2) +log10(3)...+log10(n)
第二种方法:
关于斯特林数,有斯特林公式:
lnN!=NlnN-N+0.5*ln(2*N*pi;也很容易得出其位数。
代码:
第一种方法:
第二种方法:
PS.好几天没做题了,这几天挺累的,越发觉得自己的责任所在,越发觉得自己真的该勇敢地去面对这一切,FIGHT!
[b] Big Number[/b]
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 13404 Accepted Submission(s): 5967
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
Source
Asia 2002, Dhaka (Bengal)
Recommend
JGShining
分析:
第一种方法:
N!=1*2*3....*n 要
求位数我们很自然想到对一个数取对数,
log10(n!)=log10(1)+ log10(2) +log10(3)...+log10(n)
第二种方法:
关于斯特林数,有斯特林公式:
lnN!=NlnN-N+0.5*ln(2*N*pi;也很容易得出其位数。
代码:
第一种方法:
#include<stdio.h> #include<math.h> int main() { int n,i,m; double sum; scanf("%d",&n); while(n--) { sum=0; scanf("%d",&m); for(i=1;i<=m;i++) sum+=log10((double)i); printf("%d\n",(int)sum+1); } return 0; }
第二种方法:
#include<stdio.h> #include<math.h> #define e 2.7182818284590452354 #define pi acos(-1.00) int main() { int n,i,m,sum; scanf("%d",&n); while(n--) { scanf("%d",&m); sum=(int)(1.0/2.0*log10(2.0*pi*m)+1.0*m*log10(m/e)+1); printf("%d\n",sum); } return 0; }
PS.好几天没做题了,这几天挺累的,越发觉得自己的责任所在,越发觉得自己真的该勇敢地去面对这一切,FIGHT!
相关文章推荐
- HDU1018_求数的阶乘位数
- hdu 1018 Big Number (求一个数的阶乘的位数,公式!!!)
- hdu 1018 计算一个数阶乘的位数
- HDU 2055 An easy problem(关于这道题中的一些小问题希望大家了解)
- hdu 2671(点关于直线对称问题)
- hdu 1018 Big Number (求一个数的阶乘的位数,公式!!!)
- 关于HDU1000的几个我所了解到的问题
- hdu 1284 关于钱币兑换的一系列问题 九度oj 题目1408:吃豆机器人
- 关于阶乘的问题
- HDU_1042N!(关于阶乘)
- hdu(1018)Big Number(阶乘位数的计算)
- HDU 1018 Big Number (数的阶乘的长度:数学)
- hdu 1018 求大数阶乘位数有公式
- hdu 1018 Big Number(求阶乘的位数)
- 关于阶乘的问题
- Hdu 1287 【关于异或要注意的问题】.cpp
- HDU 1018 求阶乘的位数
- HDU 1018 Big Number (阶乘位数)
- HDU 1018 Big Number(阶乘位数计算)
- HDU 1018 大数问题