hdu1018 Big Number 斯特林公式 求N!的位数。
Big Number
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 37732 Accepted Submission(s): 18174
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.
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 ≤ n ≤ 107 on each line.
10
20
19
/**
题目:Big Number
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1018
题意:求n!的位数。
思路:
斯特林公式:LL res=(long)( (log10(sqrt(4.0*acos(0.0)*n)) + n*(log10(n)-log10(exp(1.0)))) + 1 );
注意:当n=1的时候,公式不成立。自己算。 */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
const int mod=1e9+;
const int maxn=1e6+;
int T, n;
int main()
{
cin>>T;
while(T--)
{
scanf("%d",&n);
if(n==){
printf("1\n"); continue;
}
LL res=(long)( (log10(sqrt(4.0*acos(0.0)*n)) + n*(log10(n)-log10(exp(1.0)))) + );
printf("%lld\n",res);
}
return ;
}
hdu1018 Big Number 斯特林公式 求N!的位数。的更多相关文章
- 求N!的位数
#include<iostream> #include <cstdio> #include <cmath> using namespace std; const d ...
- c# 求第30位数的值
1,1,2,3,5,8,13,21,34,55.... 求第30位数的值: 递归方法: class Program { static void Main(string[] args) { //找规律: ...
- C语言 · 递归求二进制表示位数
算法训练 6-2递归求二进制表示位数 时间限制:10.0s 内存限制:256.0MB 问题描述 给定一个十进制整数,返回其对应的二进制数的位数.例如,输入十进制数9,其对应的二进制数 ...
- 蓝桥杯 算法训练 ALGO-151 6-2递归求二进制表示位数
算法训练 6-2递归求二进制表示位数 时间限制:10.0s 内存限制:256.0MB 问题描述 给定一个十进制整数,返回其对应的二进制数的位数.例如,输入十进制数9,其对应的二进制数是1001 ...
- nefu26(求数的位数)
Description 根据密码学需要,要计算某些数的阶乘的位数. Input 第一行为整数n ,接下来 n 行, 每行1个数m (1 ≤ m ≤ 10^7) . Output 输出m的阶乘的位数. ...
- Java实现 蓝桥杯VIP 算法训练 递归求二进制表示位数
问题描述 给定一个十进制整数,返回其对应的二进制数的位数.例如,输入十进制数9,其对应的二进制数是1001,因此位数是4. 样例输入 一个满足题目要求的输入范例. 9 样例输出 与上面的样例输入对应的 ...
- HDU 1018 Big Number (log函数求数的位数)
Problem Description In many applications very large integers numbers are required. Some of these app ...
- [BZOJ3000]Big Number(斯特林公式)
求n!在k进制下的位数,n<=1e18 斯特林公式:$n!\approx \sqrt{2\pi n}(\frac{n}{e})^n$ 在n很大的时候有较好的精度保证. $\log_{k}n!+1 ...
- HDU-Big Number (斯特林公式)
In many applications very large integers numbers are required. Some of these applications are using ...
随机推荐
- Python自带的hmac模块
Python自带的hmac模块实现了标准的Hmac算法 我们首先需要准备待计算的原始消息message,随机key,哈希算法,这里采用MD5,使用hmac的代码如下: import hmac mess ...
- JAVA call graphs JAVA调用图
https://github.com/gousiosg/java-callgraph Programs for producing static and dynamic (runtime) call ...
- jquery--动态篇
jQuery中隐藏元素的hide方法 让页面上的元素不可见,一般可以通过设置css的display为none属性.但是通过css直接修改是静态的布局,如果在代码执行的时候,一般是通过js控制元素的st ...
- [转] Matlab与C++混合编程(依赖OpenCV)
作者 zouxy09@qq.com,原文 Matlab与C++混合编程(依赖OpenCV) 之前在运行别人论文的代码的时候,经常有遇到Matlab与C++混合编程的影子.实际上就是通过Matlab的M ...
- Coherence的集群成员的离开和加入机制研究
最近在客户那里环境中coherence集群不稳定,所以找出一些文档,需要搞清楚Coherence内部的一些机制 1.集群成员的离开 关于状态的检测,官方的说法是: Death detection is ...
- Fatal error: Maximum execution time of 30 seconds exceeded in
Fatal error: Maximum execution time of 30 seconds exceeded in C:\Program Files\Apache Software Found ...
- 【前后台分离模式下,使用OAuth Token方式认证】
AngularJS is an awesome javascript framework. With it’s $resource service it is super fast and easy ...
- django迁移model到别的app中
举例: 移动 users.AccessKey 到 authentication.AccessKey中 1. 移动models到新的app中 $ mv users/models/access_key.p ...
- AbstractQueuedSynchronizer源码分析
AbstractQueuedSynchronizer源码分析 前提 AQS(java.util.concurrent.locks.AbstractQueuedSynchronizer)是并发编程大师D ...
- grid 布局 属性示例
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...