Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Notice that WolframAlpha returns a "Decimal Approximation". If you don't need absolute precision, you could do the same thing by calculating the factorials with <a href="http://en.wikipedia.org/wiki/Stirling%27s_approximation" rel="nofollow noreferrer">Stirling's Approximation</a>.</p> <p>Now, Stirling's approximation requires the evaluation of (n/e)^n, where e is the base of the natural logarithm, which will be by far the slowest operation. But this can be done using the techniques outlined in <a href="https://stackoverflow.com/questions/101439/the-most-efficient-way-to-implement-an-integer-based-power-function-powint-int/163572#163572">another stackoverflow post</a>.</p> <p>If you use double precision and repeated squaring to accomplish the exponentiation, the operations will be:</p> <ul> <li>3 evaluations of a Stirling approximation, each requiring O(log n) multiplications and one square root evaluation.</li> <li>2 multiplications</li> <li>1 divisions</li> </ul> <p>The number of operations could probably be reduced with a bit of cleverness, but the total time complexity is going to be O(log n) with this approach. Pretty manageable.</p> <p>EDIT: There's also bound to be a lot of academic literature on this topic, given how common this calculation is. A good university library could help you track it down.</p> <p>EDIT2: Also, as pointed out in another response, the values will easily overflow a double, so a floating point type with very extended precision will need to be used for even moderately large values of k and n.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload