HDU 1018 Big Number 斯特林数近似n!

题目链接:点击打开链接

斯特林数:点击打开链接

题意是计算n! 的位数

即ans = log10(n!) = log10(sqrt(2πn)) + n*log10(n/e)

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <vector>
#include <string>
#include <time.h>
#include <math.h>
#include <iomanip>
#include <queue>
#include <stack>
#include <set>
#include <map>
const int inf = 1e8;
const double eps = 1e-8;
const double pi = acos(-1.0);
template <class T>
inline bool rd(T &ret) {
    char c; int sgn;
    if(c=getchar(),c==EOF) return 0;
    while(c!='-'&&(c<'0'||c>'9')) c=getchar();
    sgn=(c=='-')?-1:1;
    ret=(c=='-')?0:(c-'0');
    while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');
    ret*=sgn;
    return 1;
}
template <class T>
inline void pt(T x) {
    if (x <0) { putchar('-');x = -x; }
    if(x>9) pt(x/10);
    putchar(x%10+'0');
}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const double Pi = acos(-1.);
const double e = 2.718281828459045;
double n;
int main(){
int T; rd(T);while(T--){   cin>>n;
		if(n == 1){puts("1");continue;}
		double ans = log10(sqrt(2.*Pi*n));
		ans += n * log10(n/e);
		cout<<fixed<<setprecision(0)<<ceil(ans)<<endl;
	}
    return 0;
}
时间: 2024-10-10 02:08:14

HDU 1018 Big Number 斯特林数近似n!的相关文章

HDU 1018 Big Number (简单数学)

Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 25649    Accepted Submission(s): 11635 Problem Description In many applications very large integers numbers are required. Some of these

HDU 1018 Big Number 数学题解

Problem 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

HDU 1018 Big Number (数学题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1018 解题报告:输入一个n,求n!有多少位. 首先任意一个数 x 的位数 = (int)log10(x) + 1; 所以n!的位数 = (int)log10(1*2*3*.......n) + 1; = (int)(log10(1) + log10(2) + log10(3) + ........ log10(n)) + 1; 1 #include<cstdio> 2 #include<cs

HDU 1018 -- Big Number (Stirling公式求n!的位数)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1018 Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 40551    Accepted Submission(s): 19817 Problem Description In many applications ver

HDU 1018 Big Number (log函数求数的位数)

Problem 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

hdu 3709 Balanced Number(平衡数)--数位dp

Balanced Number Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 9036    Accepted Submission(s): 4294 Problem Description A balanced number is a non-negative integer that can be balanced if a pi

HDU 1018 Big Number 数学题

Problem 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

HDU 1018.Big Number【7月25】

Big Number 这道题,没有什么难点什么的,就是为了涨姿势. Problem 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, y

HDU 1018 Big Number

有个数学公式计算数的阶乘位数 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include<cmath> 5 #define pi 3.141592653 6 #define E 2.718281828 7 using namespace std; 8 9 int main() 10 { 11 12 freopen("C:\\Users\\super\\Docum