Find the number of digits of a number factorial
Flyfish 2015-8-15
For example 7! =5040, the factorial result of 7 is 4 digits (10 binary)
Ask for a number of digits
1 Loop method
int get_digit_loop(int N) { int0; do { digit ++; while100); return digit;}
2 recursive mode
int get_digit_recursion(int N){ int0; 1011 + get_digit_recursion(N/10); return digit;}
3 Library functions with the math header file
int get_digit_lib(int N){ int digit = (floor) (log101; return digit;}
Find the number of digits of a number factorial
The number of digits of a number factorial can be obtained directly using LOG10
n=n!
Method 1
logten(n! )
=Log Ten(1?2?3... ..?N)
=Log Ten(1)+Log Ten(2)+... ..+Log Ten(N)
The log10n represents the logarithm of the base 10, N. The abbreviation is LGN.
Natural logarithm Natural logarithm
Natural | [' N?t? (?) R (?) L] Beauty [' n?t?r?l]
logarithm | [' l?g?r?e (?) M -r?θ-] Beauty [' l?ɡ?r?e?m]
Method 2
Using the Sterling formula
Stirling formula
Stirling ' s approximation
Stirling ' s formula
Stirling | [' St?:li?]
approximation English [?, Pr?ks? ' Me?? N] beauty [? ' Prɑks? ' Me?? n][) approximate method; approximate value of [number] approximation
Formula English [' F?? Mj?l?] Beauty [' F?rmj?l?] [Number] formula, criterion, formula, baby food
logten(n! )
=Log Ten(sq RT(2?PI?N))+N?Log Ten(N/e)
E is (mathematical constant) mathematical constants
E ≈ 2.71828
The logarithm of the base of E is called the natural logarithm (Natural logarithm)
Pi is also mathematical constant
Pi ≈ 3.14159265 Pi
The ratio of a circle ' s circumference to its diameter
The ratio of the circumference of the circle to the diameter
int digit_stirling(int n){ double PI=acos(double(-1));// PI的值=反余弦函数 -1.0为Pi, 1为0。 double e=exp(double(1));//e的值 returnfloor(log10(sqrt(2*PI*n))+n*log10(n/e))+1;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Find the number of digits of a number factorial