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 ...
随机推荐
- entity framework 6 通用数据类
原文 http://blog.csdn.net/laokaizzz/article/details/25730813 public class BaseDAL { string strConn = ...
- Mysql 配置慢查询日志(SlowQueryLog)以及使用日志分析工具
[ 查看系统关于慢查询的设置 ] mysql> show variables like '%slow%'; +---------------------------+-------------- ...
- sqlserver 2000新建sysadmin角色
新建登录:sp_addlogin 'netcafe','pubwin' netcafe是用户名,pubwin是密码,下面是msdn官方格式: sp_addlogin [ @loginame = ] ...
- Effective Java设定游戏 - 就是爱Java
首先,我们先设定游戏,一个网页游戏的基本场景,主角拥有各种能力,但一开始数值都只有系统初始,随着故事的发展,会接触到各种不同的场景,获得提升角色的道具与装备,来参与更高难度的任务. 阅读全文>& ...
- CSS--table之min-height
table中min-height不起作用. 但是height其实相当于min-height 超过的部分会自动撑开.
- 超大批量删除redis中无用key+配置
目前线上一个单实例redis中无用的key太多,决定删除一部分. 1.删除指定用户的key,使用redis的pipeline 根据一定条件把需要删除的用户统计出来,放到一个表里面,表为 del_use ...
- Vitamio视频播放
activity代码 package com.hck.player.ui; import io.vov.utils.StringUtils; import io.vov.vitamio.LibsChe ...
- 求解答,Android源码编译时怎样添加第三方jar包
各位大神好,遇到的问题如标题. 我用Eclipse写了一个android工程,但是这个工程需要到SDK的隐藏类,所有想在源码下编译,但是每次mm之后,都会出现错误,提示是找不到对应的类. 我需要加入的 ...
- Unity 集成联通SDK
我相信Unity程序员都会遇到加入SDK的问题,我相信如果你不会android编程,我相信你的CPU当场计算过快而爆炸! 这里也写笔记希望能帮助大家 如果有讲错的地方,希望大家能回复并且提供答案! ...
- MD5加密算法(转)
获取字符串的MD5摘要 原文更详细: http://www.weixuehao.com/archives/474 代码如下: import java.security.MessageDigest; p ...