当前位置:网站首页>51nod 1130 n factorial length V2 (Stirling approximation)
51nod 1130 n factorial length V2 (Stirling approximation)
2022-07-06 03:48:00 【Harris-H】
51nod 1130 N The length of the factorial of V2( Stirling approximation )
Use S t i r l i n g Stirling Stirling The formula
n ! = 2 π n ( n e ) n n!=\sqrt{2\pi n}(\dfrac{n}{e})^n n!=2πn(en)n
⇒ l e n ( n ! ) = log 10 ( n ! ) + 1 \Rightarrow len(n!)=\log_{10}(n!)+1 ⇒len(n!)=log10(n!)+1
= 1 2 log 10 ( 2 π n ) + n log 10 ( n e ) + 1 =\dfrac{1}{2}\log_{10}(2\pi n)+n\log_{10}(\dfrac{n}{e})+1 =21log10(2πn)+nlog10(en)+1
Time complexity : O ( 1 ) O(1) O(1)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=1e3+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
const int hashmod[4] = {
402653189,805306457,1610612741,998244353};
#define mst(a,b) memset(a,b,sizeof a)
#define db double
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define x first
#define y second
#define pb emplace_back
#define SZ(a) (int)a.size()
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr)
void Print(int *a,int n){
for(int i=1;i<n;i++)
printf("%d ",a[i]);
printf("%d\n",a[n]);
}
template <typename T> //x=max(x,y) x=min(x,y)
void cmx(T &x,T y){
if(x<y) x=y;
}
template <typename T>
void cmn(T &x,T y){
if(x>y) x=y;
}
int n;
const db pi = acos(-1.0);
int main(){
int T;scanf("%d",&T);
while(T--){
scanf("%d",&n);
//printf("%f\n",exp(1));
double s = 0.5*log10(2*pi*n)+n*log10(n/exp(1)) +1;
printf("%lld\n",(ll)s);
}
return 0;
}
边栏推荐
- [slam] orb-slam3 parsing - track () (3)
- Canvas cut blocks game code
- 【FPGA教程案例12】基于vivado核的复数乘法器设计与实现
- BUAA calculator (expression calculation - expression tree implementation)
- Mapping between QoE and KQI
- Basic concepts of LTE user experience
- Blue style mall website footer code
- Factors affecting user perception
- Image super resolution using deep revolutionary networks (srcnn) interpretation and Implementation
- UDP reliable transport protocol (quic)
猜你喜欢

Serial port-rs232-rs485-ttl

Esbuild & SWC: a new generation of construction tools

Ks003 mall system based on JSP and Servlet

Flask learning and project practice 9: WTF form verification

如何修改表中的字段约束条件(类型,default, null等)

Canvas cut blocks game code

SWC introduction

Pointer for in-depth analysis (problem solution)

2.2 STM32 GPIO操作
![[analysis of variance] single factor analysis and multi factor analysis](/img/92/5337d0ef6e487d1af2f56cb3a3268a.jpg)
[analysis of variance] single factor analysis and multi factor analysis
随机推荐
[slam] orb-slam3 parsing - track () (3)
WPF效果第一百九十一篇之框选ListBox
3.1 detailed explanation of rtthread serial port device (V1)
JS Vanke banner rotation chart JS special effect
ESBuild & SWC浅谈: 新一代构建工具
[matlab] - draw a five-star red flag
[analysis of variance] single factor analysis and multi factor analysis
2.2 STM32 GPIO操作
Crawler of explanation and application of agency theory
Error 1045 (28000): access denied for user 'root' @ 'localhost' (using password: no/yes
RT thread -- FTP of LwIP (2)
【Qt5】Qt QWidget立刻出现并消失
User experience index system
3分钟带你了解微信小程序开发
[prediction model] difference method model
Pytoch foundation - (1) initialization of tensors
Alibaba testers use UI automated testing to achieve element positioning
Image super-resolution using deep convolutional networks(SRCNN)解读与实现
C#(三十)之C#comboBox ListView treeView
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower