2009-01-13, 11:41 PM
Technically, you can generate a list of prime really fast using the 6k+/-1 rule, like what DS said, or here's another version.
First off, 2, 3, 5, 7 are the basic primes, having 5 and 7 being the first set belongs to the 6k+/-1 rule. After that, just loop:
for(i = 12; i < some_limit; i+=6)
{
if(is_prime(i-1))
// do something
if(is_prime(i+1))
// do the same thing
}
First off, 2, 3, 5, 7 are the basic primes, having 5 and 7 being the first set belongs to the 6k+/-1 rule. After that, just loop:
for(i = 12; i < some_limit; i+=6)
{
if(is_prime(i-1))
// do something
if(is_prime(i+1))
// do the same thing
}

