Big Number
问题陈述:
杭州电子科技大学 HANGZHOU DIANZI UNIVERSITY Online Judge Problem - 1018
问题解析:
公式一:
n! = 10^m => lg(10^m) = lg(n!) => m = lg(n) + lg(n-1) + lg(n-2) + ... + lg1;
所以digits = (int)m + 1;
公式二:stirling公式
n! ≈ √2PIn(n/e)n
化简:lg(n!) = 1/2lg(2*PI*n) + nlg(n/e);
代码详解:
I:
#include <iostream>
#include <cstdio>
#include <cmath> using namespace std; int main()
{
int i, n, t, digits;
double m;
cin >> n;
while(n--) {
m = ;
cin >> t;
for(i=; i<=t; i++) {
m += log10(i*1.0);
}
digits = (int)m + ;
cout << digits << endl;
}
return ;
}
II:
#include <iostream>
#include <cstdio>
#include <cmath> using namespace std; int main()
{
int n, t, digits;
double PI = acos(double(-));
double e = exp(double());
cin >> n;
while(n--) {
cin >> t;
digits = (int)(0.5*log10(*PI*t) + t*log10(t/e)) + ;
cout << digits << endl;
}
return ;
}
转载请注明出处:http://www.cnblogs.com/michaelwong/p/4287232.html
Big Number的更多相关文章
- JavaScript Math和Number对象
目录 1. Math 对象:数学对象,提供对数据的数学计算.如:获取绝对值.向上取整等.无构造函数,无法被初始化,只提供静态属性和方法. 2. Number 对象 :Js中提供数字的对象.包含整数.浮 ...
- Harmonic Number(调和级数+欧拉常数)
题意:求f(n)=1/1+1/2+1/3+1/4-1/n (1 ≤ n ≤ 108).,精确到10-8 (原题在文末) 知识点: 调和级数(即f(n))至今没有一个完全正确的公式, ...
- Java 特定规则排序-LeetCode 179 Largest Number
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
- Eclipse "Unable to install breakpoint due to missing line number attributes..."
Eclipse 无法找到 该 断点,原因是编译时,字节码改变了,导致eclipse无法读取对应的行了 1.ANT编译的class Eclipse不认,因为eclipse也会编译class.怎么让它们统 ...
- 移除HTML5 input在type="number"时的上下小箭头
/*移除HTML5 input在type="number"时的上下小箭头*/ input::-webkit-outer-spin-button, input::-webkit-in ...
- iOS---The maximum number of apps for free development profiles has been reached.
真机调试免费App ID出现的问题The maximum number of apps for free development profiles has been reached.免费应用程序调试最 ...
- 有理数的稠密性(The rational points are dense on the number axis.)
每一个实数都能用有理数去逼近到任意精确的程度,这就是有理数的稠密性.The rational points are dense on the number axis.
- [LeetCode] Minimum Number of Arrows to Burst Balloons 最少数量的箭引爆气球
There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...
- [LeetCode] Number of Boomerangs 回旋镖的数量
Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...
- [LeetCode] Number of Segments in a String 字符串中的分段数量
Count the number of segments in a string, where a segment is defined to be a contiguous sequence of ...
随机推荐
- Python爬虫使用Selenium+PhantomJS抓取Ajax和动态HTML内容
1,引言 在Python网络爬虫内容提取器一文我们详细讲解了核心部件:可插拔的内容提取器类gsExtractor.本文记录了确定gsExtractor的技术路线过程中所做的编程实验.这是第二部分,第一 ...
- checkbox选中问题
<head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312&qu ...
- Eclipse Juno 配置反编译插件
1 下载最新的jadClipse插件,地址:http://sourceforge.net/projects/jadclipse/files/jadclipse3.3/ 2 将net.sf.jadcli ...
- WPF中获取控件之间的相对位置
1,获取元素相对于父控件的位置 使用Vector VisualTreeHelper.GetOffset(Visual visual)方法,其会返回visual在其父控件中的偏移量,然后你再将返回值的V ...
- perl 爬取某理财网站产品信息
use LWP::UserAgent; use utf8; use DBI; $user="root"; $passwd="xxxxx"; $dbh=" ...
- Linux系统编程(20)——信号基本概念
信号及信号来源 信号是在软件层次上对中断机制的一种模拟,在原理上,一个进程收到一个信号与处理器收到一个中断请求可以说是一样的.信号是异步的,一个进程不必通过任何操作来等待信号的到达,事实上,进程也不知 ...
- H.264 RTP 封包格式
H.264 视频 RTP 负载格式 1. 网络抽象层单元类型 (NALU) NALU 头由一个字节组成, 它的语法如下: +---------------+ |0|1|2|3|4|5|6|7 ...
- 使用sp_configure启用 'Ad Hoc Distributed Queries'
使用sp_configure启用 'Ad Hoc Distributed Queries' 原文地址:http://blog.sina.com.cn/s/blog_531bb7630100xh88.h ...
- 导入时如何定制spring-boot依赖项的版本
spring-boot通过maven的依赖管理为我们写好了很多依赖项及其版本,我们可拿来使用.spring-boot文档介绍了两种使用方法,一是继承,二是导入. 通过<parent>继承: ...
- B-JUI(Best jQuery UI) 前端框架
From :http://b-jui.com/大略看了下还不错,收藏之.