HDU 1018 Big Number(斯特林公式 或 暴力)
来源:互联网 发布:阿里云服务器停止不了 编辑:程序博客网 时间:2024/06/02 02:32
Big Number
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 39915 Accepted Submission(s): 19434
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
21020
Sample Output
719
1.斯特林公式:N!=sqrt(2*pi*n)*pow((n/e),n);
N!的位数=log10(2*pi*n)/2+n*log10(n/e)+1;
#include <stdio.h>#include<math.h>double pi=3.14159265358;double e=2.71828182;int main(int argc, char *argv[]){int t;scanf("%d",&t);while(t--){int n;scanf("%d",&n);int ans=log10(2*pi*n)/2+n*log10(n/e)+1;printf("%d\n",ans);}return 0;}
2.暴力:每次超过10就开始去掉当前的数位 注意!!!!存阶乘的sum要用 double用long long会wa
#include <stdio.h>int main(int argc, char *argv[]){int t;scanf("%d",&t);while(t--){long long n;scanf("%lld",&n);double sum=1;int i;int cnt=1;for(i=2;i<=n;i++){sum=sum*i;if(sum>=10){while(sum>=10){sum/=10;cnt++;}}}printf("%d\n",cnt);}return 0;}
阅读全文
0 0
- HDU 1018 Big Number(斯特林公式 或 暴力)
- HDU 1018 Big Number(斯特林公式)
- HDU 1018 Big Number(斯特林公式)
- HDU 1018 Big Number(斯特林公式)
- hdu 1018 Big Number (斯特林公式)
- hdu 1018 Big Number(Stirling公式)
- hdoj 1018 Big Number(斯特林公式)
- HDUOJ 1018 Big Number (斯特林公式)
- 斯特林公式&1018 Big Number
- hdu 1018 Big Number(公式求阶乘位数)
- HDU 1018 Big Number 公式= =
- POJ - 1423 Big Number(斯特林公式)
- hdu1018 Big Number(斯特林公式)
- hdu 1018 big number (有个组合公式)
- HDU 1018(Big Number)
- Big Number(HDU 1018)
- [BZOJ3000][斯特林公式] Big Number
- hdu 1018 Big Number 两种方法 log方法(300+ms)+斯特林公式(0+ms)
- ShaderWeaver使用教程-官网信息
- 你为什么得不到梦想中的开发工作?
- 智慧科技的道德和倫理
- HDU 6170 正则表达式匹配
- centos7 快速安装gogs
- HDU 1018 Big Number(斯特林公式 或 暴力)
- 那里有外汇CRM客户管理系统源代码
- java实现上传图片的功能
- java.lang.UnsupportedClassVersionError::Class文件编译的版本错误
- 看一个数是否是素数
- BZOJ3668: [Noi2014]起床困难综合症(洛谷P2114)
- [BZOJ]2124 等差子序列 Hash&树状数组
- Myeclipse 中 项目前有感叹号是什么意思
- auto-sklearn简介