Big Number

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

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
19
 
Source
 
Recommend
JGShining
 

  
  水题,简单数学题。
  题不难,想到了就很简单。一开始想了一大堆麻烦方法,后来看别人的解题报告,发现用对数就可以解决。果然学好数学相当重要 - -|||
 
Code:
  先用递归来做,发现会超时。
 #include <iostream>
#include <cmath>
using namespace std; //用递归来做,递归方程:
//f(n) = (n==1) ? 0 : log10(n)+f(n-1)
//but 数太大会超时 double f(int n)
{
if(n==)
return ;
else
return log10(double(n))+f(n-);
}
int main()
{
int t,n;
cin>>t;
while(t--){
cin>>n;
cout<<(int)f(n)+<<endl;
}
}

  无奈换用循环,其实我是想练习一下递归的……

 #include <iostream>
#include <cmath>
using namespace std; //求阶乘值的位数可以用对数(log)来求
//例:10!的位数
// log10(10*9*8*7*6*5*4*3*2*1) + 1
// = log10(10) + log10(9) + …… + log10(2) + log10(1) + 1
// = 7
//以下使用循环来做 int main()
{
int t,n;
cin>>t;
while(t--){
cin>>n;
double sum=;
for(int i=;i<=n;i++)
sum+=log10(double(i));
cout<<int(sum)+<<endl;
}
return ;
}

Freecode : www.cnblogs.com/yym2013

hdu 1018:Big Number(水题)的更多相关文章

  1. HDU 4950 Monster (水题)

    Monster 题目链接: http://acm.hust.edu.cn/vjudge/contest/123554#problem/I Description Teacher Mai has a k ...

  2. HDU 4813 Hard Code 水题

    Hard Code Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.act ...

  3. HDU 4593 H - Robot 水题

    H - RobotTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.act ...

  4. HDOJ/HDU 2560 Buildings(嗯~水题)

    Problem Description We divide the HZNU Campus into N*M grids. As you can see from the picture below, ...

  5. hdu 1106:排序(水题,字符串处理 + 排序)

    排序 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...

  6. HDU 1018 Big Number

    LINK:HDU 1018 题意:求n!的位数~ 由于n!最后得到的数是十进制,故对于一个十进制数,求其位数可以对该数取其10的对数,最后再加1~ 易知:n!=n*(n-1)*(n-2)*...... ...

  7. HDOJ(HDU) 1859 最小长方形(水题、、)

    Problem Description 给定一系列2维平面点的坐标(x, y),其中x和y均为整数,要求用一个最小的长方形框将所有点框在内.长方形框的边分别平行于x和y坐标轴,点落在边上也算是被框在内 ...

  8. HDU - 1716 排列2 水题

    排列2 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

  9. HDU—2021-发工资咯(水题,有点贪心的思想)

    作为杭电的老师,最盼望的日子就是每月的8号了,因为这一天是发工资的日子,养家糊口就靠它了,呵呵  但是对于学校财务处的工作人员来说,这一天则是很忙碌的一天,财务处的小胡老师最近就在考虑一个问题:如果每 ...

随机推荐

  1. ios严格检验身份证号码有效性

    + (BOOL)checkIDCard:(NSString *)sPaperId { //判断位数 && sPaperId.length != ) { return NO; } NSS ...

  2. shell的执行顺序问题

    &&,||,(),{},& 五个符号的运用 shell脚本执行命令的时候,有时候会依赖于前一个命令是否执行成功.而&&和||就是用来判断前一个命令执行效果的. ...

  3. 面试题52:缺少i的乘积数组

    vector<int> multiply(const vector<int>& A) { int len = A.size(); vector<); result ...

  4. phpcms 网站迁移服务器

    相信很多人不知道怎么去把PHPCMS V9进行搬家 在本地测试好的phpcms v9网站需要搬到服务器上,可以用以下方法: 1.上传所有的程序文件(如果主机支持压缩包在线解压,那么就打成zip的包,f ...

  5. MySql 创建只读账号

    GRANT Select ON *.* TO reader@192.168.1.123  IDENTIFIED BY "123456" GRANT  可以立刻生效 在mysql 5 ...

  6. Center os FTP配置

    原文:http://www.aicoffees.com/itshare/412261137.html

  7. jQuery.parseJSON(json) 使用方法

    jQuery.parseJSON(json) 接受一个JSON字符串,返回解析后的对象. 返回值:String传入一个畸形的JSON字符串会抛出一个异常.比如下面的都是畸形的JSON字符串:{test ...

  8. delete this及堆破坏检测方法

    作者: Bruce   日期: 2012年06月03日 04:20 周日 发表评论 (0) 查看评论 --END*1--> 0 条评论 --END*2-->1,837 人阅读   程序BU ...

  9. mac os 安装 pkg-config

    wget http://pkgconfig.freedesktop.org/releases/pkg-config-0.29.tar.gz . env LDFLAGS="-framework ...

  10. 用JAVA代码实现验证邮箱地址是否符合

    public class Test{ public static void main(String[] args){ Test t = new Test(); String email = " ...