can any body inform me the best prime generating algorithm ?

Let's talk about algorithms!

Moderator: Board moderators

technobug
Learning poster
Posts: 88
Joined: Sat Nov 15, 2003 6:41 pm
Location: Brasilien
Contact:

Post by technobug »

how do i expand it to bit-wise comparison? (c/c++)

Pavl0
New poster
Posts: 16
Joined: Sun Apr 18, 2004 2:57 pm

Post by Pavl0 »

Jdont like Sieve of Eratosthenes :P

somthing like that take les memory (only prime numbers)

for(i=6;i<=2000000;i+=6)
{
for(j=0;;j++){ if((i-1)%fst[j]==0)break; if((fst[j]*fst[j])>(i-1))
{fst[liczp]=i-1; countprime++; break;}}
for(j=0;;j++){ if((i+1)%fst[j]==0)break; if((fst[j]*fst[j])>(i+1))
{fst[liczp]=i+1; countprime++; break;}}
}

check if devide by smaler prime numbers + some optimaliation
it if fast but if tou need somthing faster add fermat test

serur
A great helper
Posts: 251
Joined: Thu Feb 23, 2006 11:30 pm

Post by serur »

Seat of Eratosphenes - that's really cool!
Thank you fellows - I didn't laugh like this for a long time! :D

Post Reply

Return to “Algorithms”