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

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
Asia 2002, Dhaka (Bengal)
代码:
 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #include<algorithm>
 5 #include<cmath>
 6 using namespace std;
 7 const double e=exp(1);
 8 const double pi=acos(-1.0);
 9 int main(){
10     int t;
11     scanf("%d",&t);
12     while(t--){
13         int n;
14         scanf("%d",&n);
15         if(n==1){printf("1\n");continue;}
16         double s=log10(2.0*pi)/2.0+(n+0.5)*log10(n)-n*log10(e);
17         int ans=ceil(s);
18         printf("%d\n",ans);
19     }
20     return 0;
21 }

转载于:https://www.cnblogs.com/ZERO-/p/8440970.html

HDU 1018.Big Number-Stirling(斯特林)公式 取N阶乘近似值相关推荐

  1. 【数论】斯特林公式 ——Stirling公式(取N阶乘近似值)

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

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

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

  3. hdu 1018 Big Number(n!求位数)

    http://acm.hdu.edu.cn/showproblem.php?pid=1018 一天了,看不下数,坐不下题...唉..终于a了一道了...求n!阶乘的数的位数.才开始我直接按大数阶乘处理 ...

  4. 斯特灵公式求阶乘c语言,斯特林公式 ——Stirling公式(取N阶乘近似值)

    基于UDP协议的socket编程示例 客户端 import java.io.IOException; import java.net.DatagramPacket; import java.net.D ...

  5. HDU 1018 Big Number

    有个数学公式计算数的阶乘位数 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #i ...

  6. 杭电oj HDOJ 1018 Big Number(斯特林公式求大数阶乘的位数)

    杭电oj HDOJ 1018 Big Number 题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=1018 Problem Description In ...

  7. HDU 3826 Squarefree number:题目解答源码

    2019独角兽企业重金招聘Python工程师标准>>> HDU 3826 Squarefree number:题目解答源码 In mathematics,a squarefree n ...

  8. c语言编程cosx近似值,编程利用公式求 cosx 的近似值(精度为10-6):

    输入精度e 和实数x,用下列公式求cos x 的近似值,精确到最后一项的绝对值小于e.c语言编程, #include#include//这个函数需要返回double类型,不然结果很快就溢出了doubl ...

  9. 利用java格里高利公式求圆周率_C语言用下列公式求pi的近似值,直到最后一项的绝对值小于1e-4为止:...

    C语言 输入精度e 和实数x,用下列公式求cos x 的近似值,精确到最后一项的绝对值小于e。 #include  //头文件置顶#include double fact(int n){\ 用下面的近 ...

最新文章

  1. 独家 | Tableau中的Z-Order了解一下!
  2. C++编译期多态与运行期多态
  3. ORACLE SQL开发where子句之case-when
  4. Java虚拟机JVM常用的几种回收算法和垃圾回收器
  5. 《Head First设计模式》第八章笔记-模板方法模式
  6. 查询使用NoLock
  7. vue watch 经常监听不到_Vue.js中 watch(深度监听)的最易懂的解释
  8. tcp_v4_connect函数分析
  9. 如何去选取第一批要阅读的论文?_顶会最佳论文奖得主:初入科研领域,如何正确做科研?...
  10. android ui机制的学习笔记
  11. mock of python
  12. topjui/easyui 表格分页简单实例
  13. java生成小程序二维码
  14. 《可穿戴创意设计:技术与时尚的融合》一一2.4 超级英雄和超级可穿戴设备...
  15. PHP GD竖排文字写法
  16. 别让失败阻碍了你成功的路
  17. matlab结果输出到文本的方法
  18. IPhone弹出基于Phonegap的工程的Admob广告
  19. yarn : 无法加载文件 D:\config\node\node_global\yarn.ps1,因为在此系统上禁止运行脚本。
  20. 2023 年 Pycharm 最新安装教程,亲测可用

热门文章

  1. 十一、Shell 文件包含
  2. NX界面中获取线、面、体、特征的tag值
  3. 记一次程序员在办公室里的“撕逼”经历
  4. 港媒:AI技术有望助力中国核潜艇升级
  5. 26.Silverlight多线程技术ThreadPool的使用
  6. 如何搭建Electron开发环境
  7. IOS Key-Value Observing (KVO)
  8. action 带参数跳转
  9. sqlserver 2008 R2 删除重复数据
  10. cannot write file to virtual machine aborting the file copy operation.