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. 神经网络训练中的Tricks之高效BP(反向传播算法)

    神经网络训练中的Tricks之高效BP(反向传播算法) 神经网络训练中的Tricks之高效BP(反向传播算法) zouxy09@qq.com http://blog.csdn.net/zouxy09 ...

  2. Apache配置默认首页

    操作系统:CentOS 6.5 Apache默认主页为index.html,如果要修改为index.php或其它,需要修改httpd.conf文件 用vim或其它编辑器打开httpd.conf 在上图 ...

  3. 将对象转为数组方法:延伸array_map函数在PHP类中调用内部方法

    public static function objectToArray($d) { if (is_object($d)) { $d = get_object_vars($d); } if (is_a ...

  4. Repository

    namespace MyRepository.Domain.Infrastructure { public class Repository<TEntity> : IRepository& ...

  5. C++对象模型:单继承,多继承,虚继承

    什么是对象模型 有两个概念可以解释C++对象模型: 语言中直接支持面向对象程序设计的部分.对于各种支持的底层实现机制. 类中成员分类 数据成员分为静态和非静态,成员函数有静态非静态以及虚函数 clas ...

  6. Spring IoC实现解耦合

    public class UserDaoImpl implements UserDao{ @Override public void save(User user) { // TODO Auto-ge ...

  7. jQuery1.11源码分析(9)-----初始化jQuery对象的函数和关联节点获取函数

    这篇也没什么好说的,初始化jQuery对象的函数要处理多种情况,已经被寒冬吐槽烂了.关联节点获取函数主要基于两个工具函数dir和sibling,前者基于指定的方向遍历,后者则遍历兄弟节点(真的不能合并 ...

  8. 获取window窗口大小

    窗口大小 跨浏览器确定一个窗口的大小不是一件简单的事.IE9+.Firefox.Safari.Opera和Chrome均为此提供了4个属性:innerWidth.innerHeight.outerWi ...

  9. Powershell学习之道-文件夹共享及磁盘映射

    导读 在Linux环境下,我们很轻易就能得心应手地通过命令操作一切事物,在Windows下,Powershell也算是后起之秀,提供大量的cmdlet以及c#的横向拓展.下面将由小编带领大家通过Pow ...

  10. Nested List Weight Sum I & II

    Nested List Weight Sum I Given a nested list of integers, return the sum of all integers in the list ...