http://acm.hdu.edu.cn/showproblem.php?pid=1018                      

                        Big Number
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 40483 Accepted Submission(s): 19774

Problem Description
In many applications very large integers numbers are required. Some of these applications are using keys for secure transmission of data, encryption, etc. In this problem you are given a number, you have to determine the number of digits in the factorial of the number.

Input
Input consists of several lines of integer numbers. The first line contains an integer n, which is the number of cases to be tested, followed by n lines, one integer 1 ≤ n ≤ 107 on each line.

Output
The output contains the number of digits in the factorial of the integers appearing in the input.

Sample Input
2
10
20

Sample Output
7
19

Source
Asia 2002, Dhaka (Bengal)

分析:

斯特灵公式是一条用来取n阶乘近似值的数学公式。

公式为:

斯特林公式可以用来估算某数的大小,结合lg可以估算某数的位数,或者可以估算某数的阶乘是另一个数的倍数。

题意:
给你一个整数n,求n!的位数。
利用 求解n!的位数:

易知整数n的位数为[lgn]+1。.利用Stirling公式计算n!结果的位数时,可以两边取对数,得:
log10(n!) = log10(2*n*Pi)/2+n*log10(n/e)
则答案为:
ans = log10(2*n*Pi)/2+n*log10(n/e) + 1
其他类型题:hdu4045 hdu2521

如果是求八进制的位数呢:http://www.cnblogs.com/zhumengdexiaobai/p/8415053.html

#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
double e = 2.718281828459045;
double pi = 3.141592653589793; int main(){
int t, n;
cin >> t; while(t--){
cin >> n;
double k = log10(2 * pi * n) / 2 + n * log10(n / e);
// cout << ceil(k) << endl; //不能直接向上取整,因为若是刚好是整数,则会小1: 1.1e4,应该是4+1
cout << (int)k + 1 << endl;
} return 0;
}

  

7-n!的位数(斯特灵公式)的更多相关文章

  1. 数据结构作业——N!的位数(斯特灵公式)

    Description 求N!的位数 Input 输入第一行为一个正整数 n(1<=n<=25000). Output 输出 n!的位数. Sample Input 1020 Sample ...

  2. [牛客OI测试赛2]F假的数学游戏(斯特灵公式)

    题意 输入一个整数X,求一个整数N,使得N!恰好大于$X^X$. Sol 考试的时候只会$O(n)$求$N!$的前缀和啊. 不过最后的结论挺好玩的 $n! \approx \sqrt{2 \pi n} ...

  3. hdu1018--斯特灵公式

    斯特灵公式 Wiki http://zh.wikipedia.org/wiki/斯特林公式 /** \brief hdu 1018 * * \param date 2014/7/24 * \param ...

  4. cf932E. Team Work(第二类斯特灵数 组合数)

    题意 题目链接 Sol 这篇题解写的非常详细 首先要知道第二类斯特灵数的一个性质 \[m^n = \sum_{i = 0}^m C_{n}^i S(n, i) i!\] 证明可以考虑组合意义:\(m^ ...

  5. 斯特灵(Stirling)数

    http://zh.wikipedia.org/wiki/%E6%96%AF%E7%89%B9%E7%81%B5%E6%95%B0 第一类:n个元素分成k个非空循环排列(环)的方法总数 递推式:s(n ...

  6. HDU 1018Big Number(大数的阶乘的位数,利用公式)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1018 Big Number Time Limit: 2000/1000 MS (Java/Others) ...

  7. 斯特灵数 (Stirling数)

    @维基百科 在组合数学,Stirling数可指两类数,都是由18世纪数学家James Stirling提出的. 第一类 s(4,2)=11 第一类Stirling数是有正负的,其绝对值是个元素的项目分 ...

  8. Examining the Rooms(dp,斯特灵数)

    Examining the Rooms Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  9. HDU 3625 Examining the Rooms【第一类斯特灵数】

    <题目链接> <转载于 >>> > 题目大意:有n个锁着的房间和对应n扇门的n把钥匙,每个房间内有一把钥匙.你可以破坏一扇门,取出其中的钥匙,然后用取出钥匙打 ...

随机推荐

  1. Unable to connect to any of the specified MySQL hosts.

    c#连接Mysql数据建立连接时提示:Unable to connect to any of the specified MySQL hosts. 出现此错误的原因是Server(数据库服务器IP地址 ...

  2. boost 中文编码转换

    Lstring CHanderHttp::CircleDesc(Lint nCurCircle, Lint nMaxCircle,Lint usercount){ std::stringstream ...

  3. It is the courage

    It is the reality that a society which becomes lower and becomes weak.Believe it or not,I think it i ...

  4. Properties集合小应用--限制用户对软件的使用次数

    我们可以注意到一些付费软件可以试用一定的次数,超过限制次数后,就必须到官网购买正版才能继续使用. 这里就简单地模拟一下这种效果的实现. * 需求:记录程序的启动次数,当启动次数超过3次后,要求使用者注 ...

  5. 《DSP using MATLAB》Problem 2.14

    代码: %% ------------------------------------------------------------------------ %% Output Info about ...

  6. sql update set使用case when语句

    1. update TD_XXXsetdjyzmdm=null,djyzmsj=null,DLCS= case when DLCS is null then 1 else DLCS+1 end whe ...

  7. 东芝笔记本Satellite M40-A

    1. 问题:开机F2/Fn+F2进入不了BIOS 原因:当安装了Windows10/Windows8并且开启了快速启动,开机F2会进入不了BIOS或者F12进入不了U盘启动选择 解决方法:进入 开始- ...

  8. 玩转Panabit 2008 Live CD到U盘,Panabit随身行

    直接将Panabit 2008 Live CD的内容复制到U盘,即把Live CD转成U盘启动盘,U盘可写,方便保存配置.要能正常使用,必须机器支持USB启动,才能用上:但是熟悉此方法,同样可以灵活用 ...

  9. python 书籍推荐 三

    主要先学习<python语言入门>学完后,研究<征服python>Python简明教程(A Byte of Python) 此书讲解简洁易懂,适合初学者 剖析Python源代码 ...

  10. java的按值传递与按引用传递

    还是比较混乱 主要看怎么理解了 java没有指针一说是因为jvm将指针给隐藏了起来 说到底还是靠地址 按值传递显然直接将内存空间的内容传递给对方 之后再与传递者无关 引用是在栈空间建一个堆空间对象的映 ...