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 ...
随机推荐
- POJ 3666 Making the Grade (DP滚动数组)
题意:农夫约翰想修一条尽量平缓的路,路的每一段海拔是A[i],修理后是B[i],花费|A[i] – B[i]|,求最小花费.(数据有问题,代码只是单调递增的情况) #include <stdio ...
- JavaScript高级程序设计39.pdf
第13章 事件 JavaScript与HTML之间的交互式通过事件来实现的. 事件流 事件流描述的是从页面中接收事件的顺序,IE和Netscape提出了完全相反的事件流概念,IE是事件冒泡流,Nets ...
- [LeetCode] 42. Trapping Rain Water 解题思路
Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...
- Ubuntu的which、whereis、locate和find命令
which 只能寻找执行文件 ,并在PATH变量里面寻找. whereis 从linux文件数据库(/var/lib/slocate/slocate.db)寻找,所以有可能找到刚刚删除,或者没有发现新 ...
- It appears as though you do not have permission to view information for any of the services you requested
- hdoj 3336 Count the string【kmp算法求前缀在原字符串中出现总次数】
Count the string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- PAT 1016. Phone Bills
A long-distance telephone company charges its customers by the following rules: Making a long-distan ...
- android3.2以上切屏禁止onCreate()
一般切屏禁止onCreate()方法需要将activity加上属性: android:configChanges=”orientation|keyboardHidden” 但是在3.2以上就不起作用了 ...
- android_handler(三)
这篇记录 android 消息机制中,MainThread 向 WorkThread 发送消息.( MainThread → WorkThread ) 步骤: 1.准备looper对象 2.在子线程中 ...
- 二分PKU3273
<span style="color:#3333ff;">/* F - 二分 Time Limit:2000MS Memory Limit:65536KB 64bit ...