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 ...
随机推荐
- Java异常错误的面试题及答案
1) Java中什么是Exception? 这个问题经常在第一次问有关异常的时候或者是面试菜鸟的时候问.我从来没见过面高级或者资深工程师的 时候有人问这玩意,但是对于菜鸟,是很愿意问这个的.简单来说, ...
- 特性扩展:WebActivatorEx
WebActivator: PreApplicationStartMethod 属性,用于标记作为东西您获取 Web 应用程序启动时调用的方法,在Application_Start前. PostApp ...
- 2D游戏编程6—windows程序模板
// INCLUDES /////////////////////////////////////////////// #define WIN32_LEAN_AND_MEAN // just say ...
- HTML5 Canvas核心技术—图形、动画与游戏开发.pdf6
操作图像的像素:getImageData() putImageData() ImageData对象 调用getImageData()方法实际是获取了一个指向ImageData对象的引用,返回的对象包含 ...
- Kbuild文件
3 Kbuild文件 大部分内核中的Makefile都是使用Kbuild组织结构的Kbuild Makefile.这章将介绍Kbuild Makefile的语法. 对于Kbuild文件名来讲,Kbui ...
- 使用pupperlabs yum repo
http://docs.puppetlabs.com/guides/puppetlabs_package_repositories.html
- Hibernate查询之Example查询
org.hibernate.criterion.Example 类允许你通过一个给定实例构建一个条件查询. 此实例的属性值将做成查询条件. Cat cat = new Cat(); cat.setSe ...
- java转c#代码工具集合
1#:Java语言转换器助手地址:http://www.microsoft.com/en-us/download/details.aspx?id=14349 2#:Octopus的.NET转换器地址: ...
- [Angular 2] Component relative paths
Oingial aritial --> Link Take away: import { Component, OnInit } from '@angular/core'; @Component ...
- window下手动搭建 PHP+Nginx+Mysql(转)
首先还是下载 nginx: http://nginx.org/en/download.html php : http://windows.php.net/download/ mysql: ht ...