问题陈述:

  杭州电子科技大学 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的更多相关文章

  1. JavaScript Math和Number对象

    目录 1. Math 对象:数学对象,提供对数据的数学计算.如:获取绝对值.向上取整等.无构造函数,无法被初始化,只提供静态属性和方法. 2. Number 对象 :Js中提供数字的对象.包含整数.浮 ...

  2. Harmonic Number(调和级数+欧拉常数)

    题意:求f(n)=1/1+1/2+1/3+1/4-1/n   (1 ≤ n ≤ 108).,精确到10-8    (原题在文末) 知识点:      调和级数(即f(n))至今没有一个完全正确的公式, ...

  3. Java 特定规则排序-LeetCode 179 Largest Number

    Given a list of non negative integers, arrange them such that they form the largest number. For exam ...

  4. Eclipse "Unable to install breakpoint due to missing line number attributes..."

    Eclipse 无法找到 该 断点,原因是编译时,字节码改变了,导致eclipse无法读取对应的行了 1.ANT编译的class Eclipse不认,因为eclipse也会编译class.怎么让它们统 ...

  5. 移除HTML5 input在type="number"时的上下小箭头

    /*移除HTML5 input在type="number"时的上下小箭头*/ input::-webkit-outer-spin-button, input::-webkit-in ...

  6. 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.免费应用程序调试最 ...

  7. 有理数的稠密性(The rational points are dense on the number axis.)

    每一个实数都能用有理数去逼近到任意精确的程度,这就是有理数的稠密性.The rational points are dense on the number axis.

  8. [LeetCode] Minimum Number of Arrows to Burst Balloons 最少数量的箭引爆气球

    There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...

  9. [LeetCode] Number of Boomerangs 回旋镖的数量

    Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...

  10. [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 ...

随机推荐

  1. 配置sphinx

    1.先安装sphinxclient    #cd /usr/local/src    #wget http://sphinxsearch.com/files/sphinx-0.9.9.tar.gz   ...

  2. mysql索引分类及注意事项

    MYSQL索引主要分为四类:主键索引,普通索引(聚合,非聚合),唯一索引,全文索引 全文索引,主要是针对对文件,文本的检索, 比如文章, 全文索引针对MyISAM有用. 索引的原理:利用二叉树(哈希表 ...

  3. 【转】WPF - 第三方控件

    WPF - 第三方控件 目前第三方控件在网上形成巨大的共享资源,其中包括收费的也有免费的,有开源的也有不开源的,合理的使用第三方控件将使项目组的工作事半功倍.比如项目中有些复杂的业务逻辑.有些绚丽的效 ...

  4. 观点:哪些人适合做FPGA开发?(转)

    原文:http://xilinx.eetrend.com/blog/561 FPGA目前非常火,各个高校也开了FPGA的课程,但是FPGA并不是每个人都适合,FPGA讲究的是一个入道,入什么道,入电子 ...

  5. Mysql.Data的连接驱动 .net 的源码竟然在git了

    如标题 上链接:https://github.com/mysql/mysql-connector-net

  6. 自制简单表单验证relative与absolute定位

    html结构,用到了label与span <label class="relative"><input type="text" name=&q ...

  7. 不重启mysqld更改root密码

    Ever found yourself working on a MySQL server where root’s password is unavailable? It has happened ...

  8. php header调试,yii2打log

    1  通过header来强制刷新view:在页面最开始添加 <?php header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); h ...

  9. Java语言程序设计(基础篇) 第八章 多维数组

    第八章 多维数组 8.2 二维数组的基础知识 二维数组中的元素通过行和列的下标来访问. 8.2.1 声明二维数组变量并创建二维数组 下面是二维数组的语法: 数据类型[][] 数组名; int[][] ...

  10. Java程序员面试题集(116-135)

    摘要:这一部分讲解基于Java的Web开发相关面试题,即便在Java走向没落的当下,基于Java的Web开发因为拥有非常成熟的解决方案,仍然被广泛应用.不管你的Web开发中是否使用框架,JSP和Ser ...