HDOJ 1018 Big Number

来源:互联网 发布:rmvb转mov mac 编辑:程序博客网 时间:2024/06/10 08:44

来源:http://acm.hdu.edu.cn/showproblem.php?pid=1018

Big Number

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 22074    Accepted Submission(s): 9946


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
 

Source
Asia 2002, Dhaka (Bengal)
 

Recommend
JGShining   |   We have carefully selected several similar problems for you:  1013 1017 1016 1071 1003 

题意:这题就是要求一个数的阶乘结果的位数,比如输入5   由于5!=120  所以输出位数为3.

题解:这题就是利用个对数转换了下,很巧妙! log10(n!)=lg1+lg2+....lgn  这样题目就变得简单了。程序实现也很简单,在这里就不赘述了。

PS:开始我以为这题比大数阶乘还难,以为是要吧n! 计算出来再来统计位数,果断放弃了。 后来去网上找题解才知道这题根本没有那么麻烦来多行啊的代码就可以搞定。就是用了一个对数,不过我知道我自己肯定不会想到用对数来做的,自己跟本不知道math 头文件里面还包含了一个求对数的函数。 知道这点后,程序很快写好了,运行没有问题。但是第一次提交时杭电报错了!! 叫我把 log10(j)  中的j 改成double ,改完后就通过了。 但是并不知道为甚要这样,我想没必要去钻这些东西吧.

#include<iostream>#include<cmath>using namespace std;int main() {int N,i,n;  double sum,j;cin>>N;for(i=0;i<N;i++){sum=1;cin>>n;for(j=1;j<=n;j++)sum+=log10(j);cout<<(int)sum<<endl;} return 0;}



 
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 借贷宝不销账怎么办 借贷宝没有好友怎么办 身份证复制软件打不开怎么办 国政通无照片怎么办 超出五张手机卡怎么办 唐筛mom值异常怎么办 身份证没有磁了怎么办 身份证没慈了怎么办 人像比对不通过怎么办 贷上钱人脸识别老是失败怎么办 人脸识别过不去怎么办 身份证在家丢了怎么办 电脑系统安装失败怎么办 内存卡读取不了怎么办 内存卡不能用怎么办 手机不能读卡怎么办 药房读卡器坏了怎么办 u盘没反应怎么办 网页界面变小了怎么办 假警察扫身份证怎么办 做大巴查身份证怎么办 大股东分红时怎么办 相机读卡器为什么打不开怎么办 电脑无法识别读卡器怎么办 无法识别sd卡怎么办 sd卡格式不了怎么办 内存卡被写保护怎么办 qq读不出sd卡怎么办 sd卡格式化了怎么办 sd卡不能识别怎么办 相机内存卡读不出来怎么办 电脑文件无法删除怎么办 读卡器读不出内存卡怎么办 医保卡读取不了怎么办 内存卡不识别怎么办 电脑储存卡坏了怎么办 储存卡读不出来怎么办 内存卡显示受损怎么办 身份证年龄错了怎么办 身份复印件丢了怎么办 户口缺少户主页怎么办