POJ 1423:Big Number 求N的阶乘的长度 斯特林公式
2024-09-02 19:45:15
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.
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;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
最新文章
- int.Parse()之异常
- 黑马程序员_ Objective-c 之Foundation之NSNumber ,NSValue, NSDate
- 主机WIFI网络环境下,Linux虚拟机网络设置
- OpenSource.organization-in-github
- HTML DOM学习之二
- SimpleDateFormat做成员或者静态成员多线程安全隐患
- exam help
- POJ 1151 / HDU 1542 Atlantis 线段树求矩形面积并
- 信号之sigsetjmp和siglongjmp函数
- 基于Emgu CV 的手势识别实现PPT的控制放映
- AndroidStudyDemo之Android4.x介绍
- windows7在局域网中无法映射驱动器问题解决
- [SQL注入3]from_sqli_to_shell_II
- 智能卡安全机制比较系列(三) MPCOS
- Android System Property 解析
- VTune使用amplxe-cl进行Hardware Event-based Sampling Analysis 0分析
- 《Visual Studio Magazine》2013年读者选择奖—软件类
- Insertion Sort List Leetcode
- transform 各种影响
- AWS EC2服务器的HTTPS负载均衡器配置过程