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. VUE 动态切换列表active样式

    参考VUE官方文档样式绑定 https://cn.vuejs.org/v2/guide/class-and-style.html 需求是动态加载出来了所有菜单列表,点击其中一个li元素改变这个元素的背 ...

  2. linux 串口通信 编程详解

    计算机串口的引脚说明 序号 信号名称 符号 流向 功能 3 发送数据 TXD DTE→DCE DTE发送串行数据 2 接收数据 RXD DTE←DCE DTE 接收串行数据 7 请求发送 RTS DT ...

  3. coding 321

    三大原理(计算机原理.操作系统原理.编译原理)两个协议(TCP与HTTP协议)一种结构(数据结构)

  4. 回文数索引(string类erase解题)

    题目描述 给定一个仅由小写字母组成的字符串.现在请找出一个位置,删掉那个字母之后,字符串变成回文.请放心总会有一个合法的解.如果给定的字符串已经是一个回文串,那么输出-1. 输入描述: 第一行包含T, ...

  5. 「HNOI2008」玩具装箱

    传送门 Luogu 解题思路 \(\text{DP}\) 很显然: 设 \(dp_i\) 表示前 \(i\) 个玩具的最小费用,转移就是: \(dp_i = \max\limits_{0\le j & ...

  6. 动态指定日志路径(logback)

    实现日志上下文监听,添加路径变量 package com.x.x.x.listener; import ch.qos.logback.classic.Level; import ch.qos.logb ...

  7. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 按钮:按钮组

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  8. robot_framework + selenium + 上传本地文件+win7 32位

    1.下载与安装AutoIt v3  地址链接:http://pan.baidu.com/s/1hqsDFBA,我自己是32位的系统,用这个运行可以 2.安装完成后,如下图所示 3. AutoIt Wi ...

  9. uni-app小程序组建

    (1)新建组建:编辑器右击 新建组建 (2)传值 <template> <view class="myRankingList"> <block v-f ...

  10. python编写banner获取的常用模块

    模块的概念:模块也叫库,每个模块中都内置了大量的功能和函数.类和变量.它就像是积木,可以根据需要进行调用组合.模块就是程序,每个模块就是一个后缀为.py的Python程序.Python的模块分为标准模 ...