Some friends and I came up with this years ago when we were trying to generate large primes ourselves, but I'm sure it already exists somewhere in MathWorld or Wikipedia...
You can save a lot of space if, instead of computing (n-1)!, you compute the "minimal factorial" (which isn't the real name for it, that I know of).
The idea is that you don't need all the "junk" in (n-1)! - you only need a number that will be divisible by anything (n-1)! would have been divisible by.
What you do is, instead of computing 1*2*...*(n-1), you compute the prime factors for each number in 1..n-1, AND THEIR MULTIPLICITY. For example, 80 is 2^4*5, so its prime factors are 2 (with multiplicity 4), and 5 (multiplicity 1).
Now, for all the prime factors you collected, you only need to keep _the highest multiplicity_. Multiply the prime factors at the highest multiplicity for each, and you've got a number just as good as (n-1)!, but MUCH smaller. For example, you've eliminated about 2^(n/2) un-needed powers of 2, since half the numbers you were multiplying together were even...
Make sense??
In reply to Re: Prime Numbers
by RMGir
in thread Prime Numbers
by gtozoom
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |