hdu 1018 Big Number(公式求阶乘位数)
2017-02-12 15:36
381 查看
Big Number
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 36652 Accepted Submission(s): 17576
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
1题意:给你一个数a,求a!的位数,在数学中有求一个数阶乘位数公式分析: 123456=1.23456*10^5;
log10(123456)=5.09151;
log10(1.23456*10^5)=log10(1.23456)+log10(10^5)=0.09151+5;
故int(log10(n))+1 就是n的位数5! log10(5!)+1=log10(1*2*3*4*5)+1=log10(1)+log10(2)......注意log 返回的值是double 型
#include<iostream> #include<string> #include<string.h> #include<math.h> #include<algorithm> using namespace std; //10! log10(10!)+1=log10(1)+....log10(10)+1; int main() { int n; cin>>n; while(n--) { int m,i; double sum=0; cin>>m; for(i=1;i<=m;i++) { sum+=log10(i);//返回double 型 } cout<<(int)sum+1<<endl; } }
相关文章推荐
- hdu 1018 求大数阶乘位数有公式
- hdu 1018 Big Number (求一个数的阶乘的位数,公式!!!)
- hdu 1018 Big Number (求一个数的阶乘的位数,公式!!!)
- 斯特林[striling]公式(求阶乘(n!)的位数)
- HDU--1018--Big number!(计算阶乘结果的位数)
- HDU_1018_n(1e7)的阶乘的结果的位数
- hdu-1018Big Number(阶乘求位数)
- OJ上关于阶乘位数的公式
- hdu 1018 -Big Number(求n的阶乘的位数)
- HDU 1018 Big Number【阶乘位数】
- 斯特林(Stirling)公式 求大数阶乘的位数
- HDU 1018 Big Number (阶乘位数)
- 【nowcoder 算法训练3】不凡的夫夫(斯特灵公式,阶乘的位数)
- HDU 1018Big Number 【阶乘位数】
- 斯特林大数公式求阶乘位数
- hdu1018大数阶乘的位数,斯特林数的各种应用
- 杭电OJ(HDOJ)1018题:求n的阶乘位数(数学公式)
- HDU1018 Big Number(求阶乘位数)
- hdu 1018 阶乘位数
- hdu 1018 Big Number(求阶乘的位数)