http://wwwhomes.uni-bielefeld.de/achim/prime_sieve.html
take a look at this link . The running time is less than 2 sec for 10^8. On Sun, Apr 11, 2010 at 2:38 AM, Black Diamond <patidarc...@gmail.com>wrote: > i have an problem on SPOJ to find all the prime less than 10^8 > https://www.spoj.pl/problems/TDPRIMES/ > > i am using sieve of erastosthenes algorithm to find primes > my code is taking in my machine around 10.9 to 11.2 seconds > and time limit is 10 second how i can change my code or any diff logic..??? > //---------------------------------------------// > #include<cstdio> > using namespace std; > #define ten8 (100000000) > bool M[ten8]; > int main() > { > int half=10000, i,j,x=0; > for ( i = 0;i < ten8;i++) > M[i] = false; > for ( i = 2;i < ten8;i++) > { > if (M[i] == false) > { > x++; > if(x%100==1) > printf("%d\n",i); > if(i>half) > continue; > > for (int j = i * i;j < ten8;j += i) > { > M[j] = true; > } > } > } > } > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- Ram Karthik Reddy Ginuga karthik.ginuga[at]gmail.com CCNA,MCP Mozilla Campus Ambassador SPOJ world rank #1088 http://www.spoj.pl/users/karthu/ (91)40 27425999 (91)9247818845 -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
<<My+Sign.JPG>>