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. php扩展redis

    Redis安装整理(window平台) +php扩展redis 分类: Web开发2013-03-23 18:51 8258人阅读 评论(3) 收藏 举报                        ...

  2. 批处理中的echo命令图文详解

    批处理中的echo命令图文详解 1. Echo 显示当前ECHO的状态:ECHO ON 或者ECHO OFF 2. ECHO ON 将ECHO状态设置为ON,将显示命令行,也就是前面的C:\>类 ...

  3. iconv命令详解

    功能]  对于给定文件把它的内容从一种编码转换成另一种编码. [描述]  -f encoding :把字符从encoding编码开始转换. -t encoding :把字符转换到encoding编码. ...

  4. MySQL索引的创建、删除和查看

    MySQL索引的创建.删除和查看 此文转自http://blogold.chinaunix.net/u3/93470/showart_2001536.html 1.索引作用 在索引列上,除了上面提到的 ...

  5. ios开发 网络编程浅析(一)

    iphone包含了很多框架和库,从底层的套接字到不同层次的封装,可以方便地给程序添加网络功能. (1)BSD套接字.最底层的套接字,这是Unix网络开发常用的API.如果从其他系统移植程序,而程序用的 ...

  6. 新浪微博客户端(3)-封装UIBarButtonItem

    单独给NavigationBar上的两个NavigationItem设置图片显得比较麻烦,下面对创建单个UIBarButtonItem的过程进行封装. UIBarButtonItem+Extensio ...

  7. [MySql]explain用法及实践

    写在前面 explain对我们优化sql语句是非常有帮助的.可以通过explain+sql语句的方式分析当前sql语句. 例子 EXPLAIN table 显示这一行数据属于哪张表,若在查询中为sel ...

  8. 看过《大湿教我写.net通用权限框架(1)之菜单导航篇》之后发生的事(续)——主界面

    引言 在UML系列学习中的小插曲:看过<大湿教我写.net通用权限框架(1)之菜单导航篇>之后发生的事 在上篇中只拿登录界面练练手,不把主界面抠出来,实在难受,严重的强迫症啊.之前一直在总 ...

  9. ubuntu快速清理磁盘垃圾

    .快速清理磁盘垃圾 磁盘空间又不够用了?尝试在终端窗口中输入sudo apt-get autoremove然后输入sudo apt-get clean,前一个命令会卸载系统中所有未被使用的依赖关系,后 ...

  10. poj2642 The Brick Stops Here(DP基础题)

    比基础的多一点东西的背包问题. 链接:POJ2642 大意:有N种砖,每种花费p[i],含铜量c[i],现需要用M种不同的砖融成含铜量在Cmin到Cmax之间(可等于)的砖,即这M种砖的含铜量平均值在 ...