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 ...
随机推荐
- node.js 环境搭建
一 官网下载安装包 : 1.http://www.nodejs.org/download/ 选择相应的包进行安装 2.安装express : npm install -g express -gener ...
- python笔记之常用模块用法分析
python笔记之常用模块用法分析 内置模块(不用import就可以直接使用) 常用内置函数 help(obj) 在线帮助, obj可是任何类型 callable(obj) 查看一个obj是不是可以像 ...
- MVC4 + EF + System.Threading.Thread 出现的问题记录
项目要求是页面监测到后台数据库用户数据(Users)变化,前台做出相应的响应和操作. 一.参考很多资料,大概有几种方式: 参考资料地址:http://www.cnblogs.com/hoojo/p/l ...
- tar解压错误
# tar -zxvf aaa.tar.gz tar: This does not look like a tar archive tar: Skipping to next header ...
- rc.local自启动学习
在CentOS系统下,主要有三种方法设置自己安装的程序开机启动.1.把启动程序的命令添加到/etc/rc.d/rc.local文件中,比如下面的是设置开机启动httpd. #!/bin/sh # # ...
- UESTC_酱神的旅行 2015 UESTC Training for Dynamic Programming<Problem M>
M - 酱神的旅行 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit ...
- zoj3433(贪心+优先队列)
Gu Jian Qi Tan Time Limit: 2 Seconds Memory Limit: 65536 KB Gu Jian Qi Tan is a very hot Chines ...
- SQL递归查询实现跟帖盖楼效果
网易新闻的盖楼乐趣多,某一天也想实现诸如网易新闻跟帖盖楼的功能,无奈技术不佳(基础不牢),网上搜索了资料才发现SQL查询方法有一种叫递归查询,整理如下: 一.查询出 id = 1 的所有子结点 wit ...
- HTML标签的offset、client、 scroll和currentStyle属性
本文来自:http://www.cnblogs.com/quanhai/archive/2010/04/19/1715231.html offsetHeight = borderTopWidth + ...
- ComponentName的意思
ComponentName是用来打开其它应用程序中的Activity或服务的. 使用方法: Intent i=new Intent(); i.setComponent(new ComponentNam ...