version: desktop | mobile

Dave's Free Press

the Slightly Less Bad And Wrong Blog Edition

 

Recent posts

Less important journals

Search




Subscribe

rss

Journals that link here

Powered by

Bryar 3.0!
geeky silly politics rant weird meta religion music culture transport london drinking perl review language olympics media photography spam cooking sport hacking books web rsnapshot holidays film bastards whisky maths bryar etiquette yapc palm telecoms cars travel clothes environment bbc lolcats privacy amazon curry security home unix phone go latin anglo-saxon review-of-reviews linux gps deafness work radio
Wed, 27 Aug 2008

Optimising n! - revisited

For the background, see this post.

Late one night I thought that you might be able to simplify n-factorial thus:

Take the product of p(i)int(n/p(i)) for i=1 to i=Φ(n). Damnit, I wish there was a good and easy way of writing mathemagics on t'interwebnet.

Where:

  • n is the number whose factorial we wish to calculate;
  • p(i) is the ith prime number;
  • Φ(n) is the number of primes less than or equal to n

Now, without using a lookup table, p() and Φ() are hard to calculate, but at least you'd avoid a lot of the problems that come from using the stupendously big numbers that come as intermediate results in calculating factorials.

Unfortunately, that formula is wrong anyway. It's a restatement of this:

100! = 250 * 333 * 520 * 714 * 119 * ...

which came from noticing that 100! is the product of 50 numbers which have 2 as a prime factor, 33 numbers which have 3 as a prime factor, 20 numbers that have 5 as a prime factor, and so on. Unfortunately, it doesn't take account of numbers like 4 and 18 which have a repeated prime factor - 4, for example, is 2 * 2 and 18 is 2 * 3 * 3. Bother.

Posted at 17:13:10 by David Cantrell
keywords: geeky | maths
Permalink | 0 Comments

Archive

2007

Jan Feb Mar Apr
May Jun Jul Aug
Sep Oct Nov Dec
Dec
Nov
Oct
Sep
Aug
Jul
Jun
May
Apr
Mar
Feb
Jan

2006

Jan Feb Mar Apr
May Jun Jul Aug
Sep Oct Nov Dec
Dec
Nov
Oct
Sep
Aug
Jul
Jun
May
Apr
Mar
Feb
Jan

2005

Jan Feb Mar Apr
May Jun Jul Aug
Sep Oct Nov Dec
Dec
Nov
Oct
Sep
Aug
Jul
Jun
May
Apr
Mar
Feb
Jan