3
$\begingroup$

I've been doing some work with factorials and the normal way of calculating them is simply not working so well. When the numbers get really big, doing iterative multiplications is not viable and gets very memory and processor consuming.

I was wondering, what is the least computationally exhausting way of calculating the factorial of any given number?

$\endgroup$
6
  • $\begingroup$ I'm not an expert on this so I will post this as a comment: Have you tried the Stirling Approximation? It might not give you the correct value but it is usefull to do calculations with factorials such as large binomial coefficients. $\endgroup$ Commented Feb 6, 2015 at 13:13
  • $\begingroup$ vanguard2, since I'm attempting to calculate Brown Numbers (Brocard's problem) I'm not quite sure an approximation would suit in this case. $\endgroup$ Commented Feb 6, 2015 at 13:21
  • $\begingroup$ Perhaps you should have a look at this cs.stackexchange.com/questions/14456/… $\endgroup$ Commented Feb 6, 2015 at 13:23
  • $\begingroup$ When I was a kid I asked my math teacher, since we have such a simple formula for $1+2+\ldots+n$, how does the formula for $1\cdot 2\cdot\ldots\cdot n$ look like. He claimed there is no such formula, maybe even mentioned there is some approximation. I didn't believe him then and thought he just didn't know the formula by heart. $\endgroup$ Commented Feb 6, 2015 at 17:03
  • 1
    $\begingroup$ Does this answer your question? How to simplify or calculate a formula with very big factorials $\endgroup$ Commented Jun 14, 2020 at 8:12

1 Answer 1

3
$\begingroup$

Have you looked at this?

You didn't mention a language you use... I think the BigInteger Java class is a solid instrument to try.

$\endgroup$
2
  • $\begingroup$ I didn't mention a language simmply because I didn't decide on one yet. I wrote it on C# using BigInteger and the usual 1x2x...xn method but that was very slow and very memory consuming, I considered Haskell but now I'm not sure if I should use OpenCL and do GPU calculation instead. $\endgroup$ Commented Feb 6, 2015 at 19:58
  • $\begingroup$ @BernardoMeurer: If it is slow, your implementation is not good. Just use Python. Code. $\endgroup$ Commented Jun 26, 2020 at 19:06

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.