Re: (!?) need fast algorithm for computing factorials
From: Peter Ammon (peter_ammon_at_rocketmail.com)
Date: 11/07/03
- Next message: Sheldon Simms: "Re: (!?) need fast algorithm for computing factorials"
- Previous message: Allen: "division by general integer using shifts"
- In reply to: Adam Russell: "(!?) need fast algorithm for computing factorials"
- Next in thread: Sheldon Simms: "Re: (!?) need fast algorithm for computing factorials"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 07 Nov 2003 12:25:08 -0800
Adam Russell wrote:
> I am looking for the fastest algorithm for computing factorials (ex:
> 4!=4*3*2*1). This is for a programming contest I am thinking of entering.
> The program to be used is Labview and it needs to compute up to 10000!. I
> realize that these numbers will be too large for simple representation, and
> I think I can handle that. But I believe that simply multiplying each and
> every number probably is not the most efficient algorithm so would like
> advice on any numeric methods that might be quicker.
It may seem obvious, but the fastest algorithm will be a precomputed
lookup table. A quick sum of log_2 n! from n = 1 to 10000 using
Stirling's approximation and rounding up each term up to the nearest
multiple of 8 (so you don't have to use fractional bytes in your
representations), reveals that you'll need ~556163952 bits, which is
around 70 MB for a lookup table, if you use an efficient binary
representation of the results. That would easily fit in the memory of a
modern machine.
-Peter
- Next message: Sheldon Simms: "Re: (!?) need fast algorithm for computing factorials"
- Previous message: Allen: "division by general integer using shifts"
- In reply to: Adam Russell: "(!?) need fast algorithm for computing factorials"
- Next in thread: Sheldon Simms: "Re: (!?) need fast algorithm for computing factorials"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|