hdu 1018 Big Number (数学题)
Problem Description
Inmany applications very large integers numbers are required. Some of theseapplications are using keys for secure transmission of data, encryption, etc.In this problem you are given a number, you have to determine the number ofdigits in the
factorial of the number.
Input
Inputconsists of several lines of integer numbers. The first line contains aninteger n, which is the number of cases to be tested, followed by n lines, oneinteger 1 ≤ n ≤ 107 on each line.
Output
Theoutput contains the number of digits in the factorial of the integers appearingin the input.
SampleInput
2
10
20
Sample Output
7
19
/**************************************************
// 不能直接算N!,数据规模 1<N<10^7 太大,超出 2^31 的范围,所以取对数函数
// N = M*10^n n = log10(N) log10() 函数在头文件cmath中
984 MS,差点超时
************************************************/
#include <iostream>
#include<cmath>
using namespace std;
int main()
{
double sum;
int T,n;
cin>>T;
while(T--)
{
cin>>n;
sum = 1;
for(int i = 1;i<=n;i++)
sum+=log10(i);
cout<<(int)sum<<endl;
}
return 0;
}
hdu 1018 Big Number (数学题)的更多相关文章
- HDU 1018 Big Number
LINK:HDU 1018 题意:求n!的位数~ 由于n!最后得到的数是十进制,故对于一个十进制数,求其位数可以对该数取其10的对数,最后再加1~ 易知:n!=n*(n-1)*(n-2)*...... ...
- HDU 1018 Big Number (数学题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1018 解题报告:输入一个n,求n!有多少位. 首先任意一个数 x 的位数 = (int)log10(x ...
- hdu 1018:Big Number(水题)
Big Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- hdu 1018 Big Number 数学结论
Big Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- HDU 1018 Big Number【斯特林公式/log10 / N!】
Big Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- HDU 1018 Big Number (log函数求数的位数)
Problem Description In many applications very large integers numbers are required. Some of these app ...
- HDU 1018 Big Number 数学题解
Problem Description In many applications very large integers numbers are required. Some of these app ...
- HDU 1018 Big Number 斯特林公式
Big Number 题意:算n!的位数. 题解:对于一个数来算位数我们一般都是用while去进行计算,但是n!这个数太大了,我们做不到先算出来在去用while算位数. while(a){ cnt++ ...
- HDU 1018 Big Number (阶乘位数)
题意: 给一个数n,返回该数的阶乘结果是一个多少位(十进制位)的整数. 思路: 用对数log来实现. 举个例子 一个三位数n 满足102 <= n < 103: 那么它的位数w 满足 w ...
随机推荐
- linux 多线程基础2
6. 名称:: pthread_detach 功能: 使线程进入分离状态. 头文件: #include <pthread.h> 函数原形: int pthread_detach(pthre ...
- YII 表单验证规则
官方文档:http://www.yiichina.com/guide/form.model 类参考手册:http://www.yiichina.com/api/CValidatorhttp://www ...
- nginx定时备份access访问日志并重启nginx
用.sh脚本写了备份日志脚本 其实就是转移文件改名后重新建一个空文件 mv /alidata/log/nginx/access/wxtest.log /alidata/log/nginx/access ...
- java小算法—大衍数列
题目: 中国古代文献中,曾记载过“大衍数列”, 主要用于解释中国传统文化中的太极衍生原理. 它的前几项是:0.2.4.8.12.18.24.32.40.50 ... 其规律是:对偶数项,是序号平 ...
- C#验证邮件
public static bool IsEmail(string email) { String strExp = @"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+( ...
- linux jdk tomcat
linux jdk tomcat mysql的安装 mysql的话,推荐使用命令行安装,而不是用外部的源码去编译,因为简单粗暴. mysql服务:sudo apt-get install mysql- ...
- Swift开发:NSLayoutConstraint纯代码实现自动布局-初级篇
要求 宽高200的view,通过代码,使得view在距离父控件的右下角20边距处 /* 约束的设置,控件内部约束由自己添加,比如宽高,如果是与其他的 控件约束那么有父控件添加 *创建约束 NSLayo ...
- KDB调试内核
http://www.ibm.com/developerworks/cn/linux/l-kdbug/
- linux ptrace II
第一篇 linux ptrace I 在之前的文章中我们用ptrace函数实现了查看系统调用参数的功能.在这篇文章中,我们会用ptrace函数实现设置断点,跟代码注入功能. 参考资料 Playing ...
- gson使用详解
昨天读一篇文章,看到gson这个词,一开始还以为作者写错了,问了度娘之后才发现是我才疏学浅,于是大概了解了一下gson用法,总体来说还是很简单的. Gson.jar下载 JavaBean转json / ...