最近一堆题目要补,一直咸鱼,补了一堆水题都没必要写题解。备忘一下这个公式。

Stirling公式的意义在于:当n足够大时,n!计算起来十分困难,虽然有很多关于n!的等式,但并不能很好地对阶乘结果进行估计,尤其是n很大之后,误差将会非常大。但利用Stirling公式可以将阶乘转化成幂函数,使得阶乘的结果得以更好的估计。而且n越大,估计得越准确。

传送门:_(:з」∠)_

再来一个详细一点的,传送门:( ・´ω`・ )

Big Number

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 40645    Accepted Submission(s): 19863

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
 
 
 
代码:
 #include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const double e=exp();
const double pi=acos(-1.0);
int main(){
int t;
scanf("%d",&t);
while(t--){
int n;
scanf("%d",&n);
if(n==){printf("1\n");continue;}
double s=log10(2.0*pi)/2.0+(n+0.5)*log10(n)-n*log10(e);
int ans=ceil(s);
printf("%d\n",ans);
}
return ;
}
 

HDU 1018.Big Number-Stirling(斯特林)公式 取N阶乘近似值的更多相关文章

  1. 斯特林公式 ——Stirling公式(取N阶乘近似值)(转)

    斯特灵公式是一条用来取n阶乘近似值的数学公式.一般来说,当n很大的时候,n阶乘的计算量十分大,所以斯特灵公式十分好用.从图中可以看出,即使在n很小的时候,斯特灵公式的取值已经十分准确. 公式为:    ...

  2. HDU 1018 Big Number

    LINK:HDU 1018 题意:求n!的位数~ 由于n!最后得到的数是十进制,故对于一个十进制数,求其位数可以对该数取其10的对数,最后再加1~ 易知:n!=n*(n-1)*(n-2)*...... ...

  3. HDU 1018 Big Number(数论,Stirling公式)

    1. 利用数学公式lg(n!)=lg(2)+lg(3)+....+lg(n) 求解 2.

  4. HDU 1018 Big Number 斯特林公式

    Big Number 题意:算n!的位数. 题解:对于一个数来算位数我们一般都是用while去进行计算,但是n!这个数太大了,我们做不到先算出来在去用while算位数. while(a){ cnt++ ...

  5. HDU 1018 Big Number (数学题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1018 解题报告:输入一个n,求n!有多少位. 首先任意一个数 x 的位数 = (int)log10(x ...

  6. hdu 1018 Big Number (数学题)

    Problem Description Inmany applications very large integers numbers are required. Some of theseappli ...

  7. HDU 1018 Big Number【斯特林公式/log10 / N!】

    Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  8. HDU 1018 Big Number (log函数求数的位数)

    Problem Description In many applications very large integers numbers are required. Some of these app ...

  9. hdu 1018:Big Number(水题)

    Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

随机推荐

  1. C++简易酒店管理系统,实现(查询、入住、退房、楼层选择、退出)功能

    #include <iostream> #include <string.h> #include <stdlib.h> void enter(); void che ...

  2. 使用powershell批量更新git仓库

    Get-ChildItem D:\GitHub\NetCore | ForEach-Object -Process{ cd $_.name; git pull; cd ../ }

  3. linux文件属性之linux文件删除原理

    Linux是通过link的数量来控制文件删除的,只有当一个文件不存在任何link的时候,这个文件才会被删除.一般来说,每个文件都有2个link计数器:i_count和i_nlink. i_count的 ...

  4. linux文件属性软硬链接知识

    链接的概念 在linux系统中,链接可分为两种:一种为硬链接,另一种为软链接或符号链接.在默认不带参数的情况下,执行ln命令创建的链接是硬链接. 如果使用ln  -s创建链接则为软链接,前面文件类型为 ...

  5. leetcode-15-basic-string

    58. Length of Last Word 解题思路: 从结尾向前搜索,空格之前的就是最后一个词了.写的时候我考虑了尾部有空格的情况.需要注意的是,测试用例中有" "的情况,此 ...

  6. selenium2中的TestNg注解和数据驱动的简介及使用

    TestNg常用注解介绍,先来张图: 先看一下,以上各个注释的运行次序: @Test 表示的意义:    1.表示示该方法是一个测试方法,在运行时,会自动的运行有@Test注脚的方法. 示例: @Be ...

  7. bash脚本编写基础

    bash脚本编程     命令的堆砌     脚本程序:解释器解析执行     shell:交互式接口,编程环境         shell:能够提供一些内部命令,并且能通过PATH环境变量找到外部命 ...

  8. luogu2590 [ZJOI2008]树的统计

    树剖裸题 #include <iostream> #include <cstdio> using namespace std; int n, uu, vv, hea[30005 ...

  9. day03_02 Python版本的选择

    总结:python2.x是遗产(过时),python3.x是现在和未来的语言 In summary : Python 2.x is legacy, Python 3.x is the present ...

  10. chardet的下载及安装

    1.chardet下载地址 https://pypi.python.org/pypi/chardet/3.0.4#downloads 2.解压至安装路径 D:\Program Files (x86)\ ...