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;
}

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

最新文章

  1. int.Parse()之异常
  2. 黑马程序员_ Objective-c 之Foundation之NSNumber ,NSValue, NSDate
  3. 主机WIFI网络环境下,Linux虚拟机网络设置
  4. OpenSource.organization-in-github
  5. HTML DOM学习之二
  6. SimpleDateFormat做成员或者静态成员多线程安全隐患
  7. exam help
  8. POJ 1151 / HDU 1542 Atlantis 线段树求矩形面积并
  9. 信号之sigsetjmp和siglongjmp函数
  10. 基于Emgu CV 的手势识别实现PPT的控制放映
  11. AndroidStudyDemo之Android4.x介绍
  12. windows7在局域网中无法映射驱动器问题解决
  13. [SQL注入3]from_sqli_to_shell_II
  14. 智能卡安全机制比较系列(三) MPCOS
  15. Android System Property 解析
  16. VTune使用amplxe-cl进行Hardware Event-based Sampling Analysis 0分析
  17. 《Visual Studio Magazine》2013年读者选择奖—软件类
  18. Insertion Sort List Leetcode
  19. transform 各种影响
  20. AWS EC2服务器的HTTPS负载均衡器配置过程

热门文章

  1. springcloud gateway 项目打包部署运行
  2. 「NOIP2015」运输计划
  3. Flask与Django哪个更好更实用呢?砖家是这么认为的
  4. Spring Boot 学习(一)
  5. instance与可变参数合用,多态性
  6. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 按钮:按钮标签
  7. C++Review15_内存管理
  8. 洛谷P1351 联合权值
  9. SpringIOC初始化过程源码跟踪及学习
  10. Azure Cognitive Services- Speech To Text