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. SpringBoot 静态资源的配置

    springboot默认的静态资源目录: classpath:/static classpath:/public classpath:/resources classpath:/META-INF/re ...

  2. PHP+MySQL实现在线测试答题实例

    这个实例主要给大家介绍如何使用jQuery+PHP+MySQL来实现在线测试题,包括动态读取题目,答题完毕后台评分,并返回答题结果. 读取答题列表: $sql = "select * fro ...

  3. 用sql删除数据库重复的数据的方法

      /***********************************************两个意义上的重复记录:1.是完全重复的记录,也即所有字段均重复的记录,2.是部分关键字段重复的记录, ...

  4. redis集群JedisCluster连接关闭问题

    JedisCluster连接关闭问题 set方法为例 //伪代码 JedisCluster jedisCluster = new JedisCluster(); jedisCluster.set(&q ...

  5. 最新版本GIT安装

    版本问题,最直接的解决办法就是重新编辑安装git吧: 1. 下载:# wget -O git.zip https://github.com/git/git/archive/master.zip 2. ...

  6. 5G大潮下卖点越来越少的苹果,会成为下一个诺基亚吗?

    当下,5G显然成为手机厂商继全面屏.AI等之后,又一个重要的风口.为了赶上这个风口,很多厂商不惜寻找各种噱头去吸引大众的关注.比如小米在发布MIX 3之前疯狂造势称要发布5G版,但在10月25日的发布 ...

  7. Adobe Illustrator CC 2017安装方法

    1.下载软件地址 2017破解版32位64位中文版下载[百度网盘资源地址]:https://pan.baidu.com/s/13BsU8CfsLB6OXr7SkRFzCg 注意:使用之前请关闭杀毒软件 ...

  8. iOS 十种线程锁

    锁 是什么意思? 我们在使用多线程的时候多个线程可能会访问同一块资源,这样就很容易引发数据错乱和数据安全等问题,这时候就需要我们保证每次只有一个线程访问这一块资源,锁 应运而生. 这里顺便提一下,上锁 ...

  9. C语言备忘录——运算符优先级

    丢脸啊,今天写一道算法题,第一次没写对.改了半天愣是没看出来错哪,后面说出了一下过程,突然发现是运算符优先级惹得祸 if (!num % 2){ …… },!的运算优先级高于%,啊啊啊,丧心病狂我找了 ...

  10. Spring入门之四-------SpringIoC之其他知识点

    一.懒加载 public class Bean1 { public Bean1() { System.out.println(this.getClass().getSimpleName() + &qu ...