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. 6-17 Shortest Path [2](25 分)

    Write a program to find the weighted shortest distances from any vertex to a given source vertex in ...

  2. 抽取JDBCTemplate

    抽取JDBCTemplate 为了解决DAO实现类中代码的重复问题,另外使得代码更通用,所以抽取一个公共的模板,使其更具有通用性. DAO实现类的代码 public class StudentDAOI ...

  3. Cockpit 容器&&kubernetes 管理可视化工具

    安装 在k8s 的master 上 yum install -y cockpit cockpit-ws cockpit-kubernetes cockpit-bridge cockpit-dashbo ...

  4. 转 HTTP.SYS 详解

    http.sys 是一个位于Win2003和WinXP SP2中的操作系统核心组件, 能够让任何应用程序通过它提供的接口,以http协议进行信息通讯. 温馨提示:如果用户不慎删除了该驱动文件,不用担心 ...

  5. 关于location.href赋值的php用法

    <?php echo $_GET['action']; ?> <!doctype html> <html lang="zh"> <head ...

  6. string,char*及CString类型的相互转换

    首先先介绍一下什么是CString CString是MFC的字符串类,它不是基本类型,而是对字符串的封装,它是自适应的,在UNICODE环境下就是CStringW,在非UNICODE环境下就是CStr ...

  7. bzoj3191卡牌游戏

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3191 原本想模拟过程,从t个人推到1个人: 但是怎么转移呢?想状压,可是50位压不到角标里. ...

  8. Nagios配置文件说明

    Lepus 安装配置:http://www.cnblogs.com/xuanzhi201111/p/5200757.html Nagios 各个目录用途说明如下:bin                ...

  9. WCF揭秘学习笔记(2):数据表示

    背景知识 WCF提供了一种语言为软件通信建模,称作服务模型.使用更底层的编程架构提供的类可以从这种语言建立的模型中生成可用的通信软件. 在服务模型使用的语言中,负责通信的软件部分称为服务(servic ...

  10. 文件读取错误UnicodeDecodeError: 'utf-8' codec can't decode byte 0x92 in position 884: invalid start byte

    参考: https://segmentfault.com/q/1010000004268196/a-1020000004269556 ubuntu下Python3使用open('filename', ...