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 ...
随机推荐
- 破解安装 SecureCRT 7.0.2 for mac完美破解版,mac secureCRT , apple secureCRT
mac secureCRT , apple secureCRT 下载地址:http://download.csdn.net/detail/guolichun/7733069 破解安装 SecureC ...
- asp.net用户检测的两种方式
第一种方式(继承System.Web.UI.Page类,重写OnInit方法): public class CheckSession : System.Web.UI.Page { ...
- [SAM4N学习笔记]UART的使用
一.准备工作: 将上一节搭建的工程复制一份,命名为"3.uart".这一节主要讲如何使用SAM4N的UART功能,实现串口的收发. 二.程序编写: 细心看数据手册的朋友也 ...
- ambari的重新安装
ambari是什么呢? 这里我简单说一下ambari的目的,他的目的就是简化hadoop集群的安装和管理.对于安装简化到什么地步呢?只需要几个命令,在页面上配置几个参数,几百几千个节点的集群就能安装成 ...
- 如何实例化i2c_client(四法)
一.在板文件进行client的实例化 在内核的初始化中(例如在板文件中)定义设备的信息.这种操作的前提是内核编译的时候已经确定有哪些i2c设备和它们的地址,还要知道连接的总线的编号. 比如在板文件/a ...
- MongoDB:The Definitive Guide CHAPTER 1 Introduction
MongoDB is a powerful, flexible, and scalable data store. It combines the ability to scale out with ...
- jQuery 的属性操作方法
jQuery 属性操作方法 下面列出的这些方法获得或设置元素的 DOM 属性. 这些方法对于 XML 文档和 HTML 文档均是适用的,除了:html(). 方法 描述 addClass() 向匹配的 ...
- Codeforces Round #198 (Div. 2) D. Bubble Sort Graph (转化为最长非降子序列)
D. Bubble Sort Graph time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 局域网内使用linux的ntp服务
假设我们的饿局域网无法连接外网,但又需要同步时间,怎么办? 1. 已局域网内的一台机器作为基础,适用date修改其他机器的时间,date -s ...,很不方便,这里不介绍. 2. 适用ntp服务,自 ...
- java定义类 对象,引用,指针
java是根据面向对象编程,因此有类和对象的概念,类分为普通类与抽象类. 一.定义类 类由N个 构造器 成员变量 方法组成,可以不定义,也可以根据语法定义N个. [修饰符] class 类名{ 构 ...