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. 初学structs2,简单配置

    一.structs2-demo1项目下新建structs.xml文件,文件名必须是structs 二.package节点配置及其子节点配置 <!--name:单纯给包起个名字,保证和其他包不重名 ...

  2. Glut 回调函数小结

    2014-04-08  16:25:50   void glutDisplayFunc(void (*func)(void)); 注册当前窗口的显示回调函数 参数: func:形为void func( ...

  3. gdb命令与调试方法

    单线程 http://www.cnblogs.com/lidabo/p/5629830.html 编译程序一定要加-g选项 gcc -g test.c -o test 进入gdb调试:gdb 程序名 ...

  4. php中mysql参数化查询

    $query = sprintf("SELECT * FROM Users where UserName='%s' and Password='%s'",mysql_real_es ...

  5. CentOS 7 使用经验(更新中)

    首先说一下写这篇博客的初衷. 由于公司这一期的产品准备支持的环境有CentOS 7.MySql 5.6.Java 8.Tomcat 8等等,并且因为人员严重不足,我本月的开发任务在原有的基础上又加上了 ...

  6. 只能输入汉字js脚本

    <html> <head> <meta http-equiv="Content-Type" content="text/html" ...

  7. Git+Gradle+Eclipse构建项目

    步骤: 1.安装好Git.解压gradle-2.14.zip免安装文件: 2.用SourceTree将GitLab上的项目拉取下来: 3.打开eclipse->Import->Gradle ...

  8. sql重复记录查询

    1.查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断 select * from people where peopleId in (select  peopleId  fro ...

  9. PyOpenGL利用文泉驿正黑字体显示中文字体

    摘要:在NeHe的OpenGL教程第43课源代码基础上,调用文泉驿正黑字体实现中文字体的显示 在OpenGL中显示汉字一直是个麻烦的事情,很多中文书籍的文抄公乐此不疲地介绍各种方法及其在windows ...

  10. 完善dedecms站内搜索代码,为搜索结果添加第*页

    自那些平凡而伟大的程序猿开发了内容管理系统(cms),为了让看客们更快地找到自己感兴趣的内容,他们不断完善站内搜索代码,形成了一个小型的站内搜索引擎.可能有些网站模板设计师没考虑到seo的问题,很多站 ...