当前位置:网站首页>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;
}
边栏推荐
- Image super-resolution using deep convolutional networks(SRCNN)解读与实现
- 如何修改表中的字段约束条件(类型,default, null等)
- 在字节做测试5年,7月无情被辞,想给划水的兄弟提个醒
- 3.2 detailed explanation of rtthread serial port device (V2)
- Indicator system of KQI and KPI
- MySQL 中的数据类型介绍
- Flask learning and project practice 9: WTF form verification
- mysql关于自增长增长问题
- 【按键消抖】基于FPGA的按键消抖模块开发
- 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
猜你喜欢
An article will give you a comprehensive understanding of the internal and external components of "computer"
数据分析——seaborn可视化(笔记自用)
Force buckle 1189 Maximum number of "balloons"
SWC介绍
Teach you to build your own simple BP neural network with pytoch (take iris data set as an example)
Overview of super-resolution reconstruction of remote sensing images
[Massey] Massey font format and typesetting requirements
2.13 weekly report
C (XXIX) C listbox CheckedListBox Imagelist
Record the process of reverse task manager
随机推荐
Pandora IOT development board learning (HAL Library) - Experiment 9 PWM output experiment (learning notes)
3.2 rtthread 串口设备(V2)详解
施努卡:什么是视觉定位系统 视觉系统如何定位
Introduction to data types in MySQL
MySQL 中的数据类型介绍
[practice] mathematics in lottery
[American competition] mathematical terms
Svg drag point crop image JS effect
【Rust 笔记】18-宏
在字节做测试5年,7月无情被辞,想给划水的兄弟提个醒
Prime protocol announces cross chain interconnection applications on moonbeam
【FPGA教程案例12】基于vivado核的复数乘法器设计与实现
C form application of C (27)
three. JS page background animation liquid JS special effect
BUAA magpie nesting
Blue Bridge Cup - day of week
Image super-resolution using deep convolutional networks(SRCNN)解读与实现
[001] [stm32] how to download STM32 original factory data
KS008基于SSM的新闻发布系统
Ks003 mall system based on JSP and Servlet