当前位置:网站首页>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;
}
边栏推荐
- mysql从一个连续时间段的表中读取缺少数据
- RT-Thread--Lwip之FTP(2)
- 施努卡:什么是视觉定位系统 视觉系统如何定位
- [prediction model] difference method model
- Network security - Security Service Engineer - detailed summary of skill manual (it is recommended to learn and collect)
- Remote Sensing Image Super-resolution and Object Detection: Benchmark and State of the Art
- [slam] lidar camera external parameter calibration (Hong Kong University marslab) does not need a QR code calibration board
- Cf603e pastoral oddities [CDQ divide and conquer, revocable and search set]
- 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
- C#(三十)之C#comboBox ListView treeView
猜你喜欢

2. GPIO related operations

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

多项目编程极简用例

MySQL reads missing data from a table in a continuous period of time

User experience index system

C#(三十)之C#comboBox ListView treeView

C#(二十九)之C#listBox checkedlistbox imagelist

Cubemx transplantation punctual atom LCD display routine

Alibaba testers use UI automated testing to achieve element positioning

C#(二十八)之C#鼠标事件、键盘事件
随机推荐
Facebook and other large companies have leaked more than one billion user data, and it is time to pay attention to did
遥感图像超分辨重建综述
1.16 - check code
Pytoch foundation - (2) mathematical operation of tensor
[prediction model] difference method model
2.13 weekly report
Facebook等大廠超十億用戶數據遭泄露,早該關注DID了
Suggestions for new engineer team members
Pytorch load data
C (thirty) C combobox listview TreeView
Remote Sensing Image Super-resolution and Object Detection: Benchmark and State of the Art
three. JS page background animation liquid JS special effect
[optimization model] Monte Carlo method of optimization calculation
Deno介绍
潘多拉 IOT 开发板学习(HAL 库)—— 实验9 PWM输出实验(学习笔记)
Flask learning and project practice 8: introduction and use of cookies and sessions
2.1 rtthread pin device details
Oracle ORA error message
2.2 fonctionnement stm32 GPIO
WPF effect Article 191 box selection listbox