2

I was solving some permutation, combination problems where we know that we are to use factorial. So I was thinking if there was any shorter way, maybe a formula, than multiplying all the numbers till $n$ to find $n$!

I know how to add series like $1+2+3+4+…+n$ which is $\frac{n(n+1)}{2}$ but I didn't find much on how to multiply. So... how to do it then?

1 Answers1

0

After your editing of the original question:

You will not find an easy formula for the exact evaluation of factorials, except using $n! = \Gamma(n+1)$. If you want to compute faster than just multiply the numbers, use e.g. the prime power table approch.

A basic fast algorithm is described in P.B. Borwein, On the complexity of calculating factorials, Journal of Algorithms, Vol.6, pp. 376-380, 1985. Available as http://www.cecm.sfu.ca/personal/pborwein/PAPERS/P29.pdf

Here the four steps of Borwein's algorithm for $n!$:

  1. Construct the prime table $2 \le p_k \le n\;$ (e.g. using a sieve method)

  2. Compute the exponents of the $p_k$ in $n!\;$ (e.g. Legendre's formula)

  3. Compute $O(\log n)$ numbers $\alpha_i$ (for details see the paper)

  4. Compute $n! = \prod \alpha_i$

For actual implementations see e.g. the mentioned FastFactorial Functions page.

gammatester
  • 18,827