Big Number
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 27027   Accepted: 8626

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 <= m <= 10^7 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

题意是要求N!有多少位。

因为有斯特林公式,所以求n!的位数即log10(n)=log10(sqrt(2*acos(-1.0)*n))+n*log10(n/exp(1.0));

代码:

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#pragma warning(disable:4996)
using namespace std; int main()
{
int test;
long long n; cin >> test;
while (test--)
{
cin >> n;
double re = log10(sqrt(2 * acos(-1.0)*n)) + n*log10(n / exp(1.0));
cout << (int)re + 1 << endl;
}
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

POJ 1423:Big Number 求N的阶乘的长度 斯特林公式的更多相关文章

  1. POJ 1401:Factorial 求一个数阶乘的末尾0的个数

    Factorial Time Limit: 1500MS   Memory Limit: 65536K Total Submissions: 15137   Accepted: 9349 Descri ...

  2. POJ 1423 Big Number

    题意:求n阶乘的位数. 解法:斯特林公式,,然后取log10就是位数了,因为精度问题需要化简这个式子,特判1. 代码: #include<stdio.h> #include<iost ...

  3. POJ 2104 K-th Number ( 求取区间 K 大值 || 主席树 || 离线线段树)

    题意 : 给出一个含有 N 个数的序列,然后有 M 次问询,每次问询包含 ( L, R, K ) 要求你给出 L 到 R 这个区间的第 K 大是几 分析 : 求取区间 K 大值是个经典的问题,可以使用 ...

  4. 汇编语言-求X的阶乘

    1. 题目:求X的阶乘值 2. 要求:输入一个整型数(不超过10),求出其阶乘值后输出,求阶乘的算法用子程序来实现. 3. 提示:可以用递归来实现,也可以用简单的循环来实现. 这里使用循环来实现: 对 ...

  5. poj 2104 K-th Number 主席树+超级详细解释

    poj 2104 K-th Number 主席树+超级详细解释 传送门:K-th Number 题目大意:给出一段数列,让你求[L,R]区间内第几大的数字! 在这里先介绍一下主席树! 如果想了解什么是 ...

  6. POJ 3080 Blue Jeans (求最长公共字符串)

    POJ 3080 Blue Jeans (求最长公共字符串) Description The Genographic Project is a research partnership between ...

  7. poj 1474 Video Surveillance - 求多边形有没有核

    /* poj 1474 Video Surveillance - 求多边形有没有核 */ #include <stdio.h> #include<math.h> const d ...

  8. C语言-求1-20的阶乘的和(函数的递归)

    // //  main.c //  C语言 // //  Created by wanghy on 15/9/5. //  Copyright (c) 2015年 wanghy. All rights ...

  9. 递归和非递归分别实现求n的阶乘

    思路:举例求6的阶乘,6*5*4*3*2*1.可以将5开始看成另一个整型变量n,用一个循环每次将n的值减少1,.而递归也是如此,每次调用函数的时候将变量减一就可以. 方法一:非递归 //非递归: #i ...

随机推荐

  1. jquery获取select选中的文本值

    误区: 一直以为jquery获取select中option被选中的文本值,是这样写的:   $("#id").text();  //获取所有option的文本值 实际上应该这样: ...

  2. spring事务代码实践

    事务一般是指数据库事务,是指作为一个程序执行单元执行的一系列操作,要么完全执行,要么完全不执行.事务就是判断以结果为导向的标准. 一.spring的特性(ACID) (1).原子性(atomicity ...

  3. 090、Java中String类之判断两个int型整数是否相等

    01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...

  4. 用绿色版TOMCAT和绿色版JDK安装一个WEB服务器

    (1) 使用绿色版本JDK,解压到一个目录上D:\jdk1.6.   (2) 使用绿色版本Tomcat,解压到另一个目录上D:\jdk1.6\tomcat5.5 只要在bat文件D:\tomcat5. ...

  5. extract()和extact_first()的区别

    extract()和extact_first()都是提取Selector的data部分.但现在你要先知道什么是Selector. Selector是选择器的意思.具体定义我不知道,但通过下面的例子,你 ...

  6. 安装双版本python2 和 python 3 所产生得问题 解决yum对python依赖版本问题

    错误 解决办法 一是升级yum  直接使用python3以上版本 二是修改yum的解释器为旧版本python2.7,即将连接文件   /usr/bin/python    软连接回   /usr/bi ...

  7. 原型与继承与class

    对象有属性(专业点叫静态属性)和方法(专业点叫静态方法)和原型属性和原型方法 除了系统自带的那么几百万个对象,我们自己写在js的创建的对象,自定义的对象,都来自对象的构造函数,用来构造对象的函数,叫做 ...

  8. 049、Java中使用switch判断,不加入break时的操作

    01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...

  9. 八、Delphi10.3读取JSON文件,并修改JSON数组一条内容后保存到文件

    一.我们有一个JSON文件,如下: { "在野": [ { "城池": 0, "武将": 74, "登场年": 190 ...

  10. JS在不改变原数组的情况下复制一个新的数组

    var a={1,2,3,4} var data= JSON.parse(JSON.stringify(a[0])) a.push(data) a[4]=5 这样就不会改变原数组a的数据