当前位置:网站首页>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;
}
边栏推荐
- 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
- P7735-[noi2021] heavy and heavy edges [tree chain dissection, line segment tree]
- Pytorch load data
- 2.2 STM32 GPIO操作
- 3分钟带你了解微信小程序开发
- C#(三十一)之自定义事件
- Network security - Security Service Engineer - detailed summary of skill manual (it is recommended to learn and collect)
- Alibaba testers use UI automated testing to achieve element positioning
- Containerization Foundation
- 施努卡:3d视觉检测应用行业 机器视觉3d检测
猜你喜欢

Remote Sensing Image Super-resolution and Object Detection: Benchmark and State of the Art

施努卡:3d视觉检测应用行业 机器视觉3d检测

JS music online playback plug-in vsplayaudio js

Pointer for in-depth analysis (problem solution)

3.1 detailed explanation of rtthread serial port device (V1)

On Data Mining

在 .NET 6 中使用 Startup.cs 更简洁的方法

SWC介绍

Scalpel like analysis of JVM -- this article takes you to peek into the secrets of JVM

Blue Bridge Cup - day of week
随机推荐
mysql关于自增长增长问题
2.2 STM32 GPIO操作
Network security - Security Service Engineer - detailed summary of skill manual (it is recommended to learn and collect)
C#(三十)之C#comboBox ListView treeView
Scalpel like analysis of JVM -- this article takes you to peek into the secrets of JVM
Ks008 SSM based press release system
[001] [stm32] how to download STM32 original factory data
UDP reliable transport protocol (quic)
2.1 rtthread pin设备详解
Facebook and other large companies have leaked more than one billion user data, and it is time to pay attention to did
Prime Protocol宣布在Moonbeam上的跨链互连应用程序
Error 1045 (28000): access denied for user 'root' @ 'localhost' (using password: no/yes
MySQL reads missing data from a table in a continuous period of time
Pointer written test questions ~ approaching Dachang
[meisai] meisai thesis reference template
How to standardize the deployment of automated testing?
Do you know cookies, sessions, tokens?
After five years of testing in byte, I was ruthlessly dismissed in July, hoping to wake up my brother who was paddling
1. New project
Alibaba testers use UI automated testing to achieve element positioning