I use GMP to calculate very large factorials (e.g. 234234!). Is there any way to find out before what calculation how many digits will be a long result (or maybe)?
The factorial locarithm can be used to calculate the number of digits that the factorial will take:
This can be easily translated into an algorithmic form:
//Pseudo-code function factorialDigits (n) var result = 0; for(i = 1; i<=n; i++) result += log10(n); return result;
You can convert the Stirling approximation formula using simple logarithmic mathematics to get the number of digits:
n! ~ sqr(2*pi*n) * (n/e)^n log10(n!) ~ log10(2*pi*n)/2 + n*log10(n/e)
, .
n!
. Wikipedia .
nlog(n) - n + log(n(1 + 4n(1 + 2n)))/6 + log(pi)/2
. " " @http://en.wikipedia.org/wiki/Factorial
: n! ~ = sqrt (2 * Pin) (n/e) ^ n. , 1 + log (n!)/Log (10).
, , ... - LUT, N . 4 4 , 1000 000 8 .
Source: https://habr.com/ru/post/1712363/More articles:Downloading your own DLL as a debugging module in C # managed code for Windows CE - c ++Unable to set breakpoints in C DLLs used by C ++ / CLI called from C # - debuggingHow can I bind a byte array in Java? - javaUsing C # to print large images across multiple pages - c #Symbol CATransform3DMakeRotation Not Found - iphoneРазработка С++ для Linux в Windows - c++https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1712365/why-doesnt-moz-border-radius-topright-work-in-google-chrome&usg=ALkJrhjzXfD2glTush52v6d-099Y7pEa1AIs fetching HTML directly from the model (MVC) a good idea? - model-view-controllerWhat other patterns / architectures like MVC exist for very flexible applications? - design-patternsWhere to store secret keys and password in Python - pythonAll Articles