Hi Dod, Could you pls expalin what this algorithm is doing and from where you got it.
Thanks Nitin On Wed, Aug 17, 2011 at 2:56 AM, Don <[email protected]> wrote: > I wrote a program to print prime numbers, but it is not very fast. Can > someone help me figure out why? > > > #include <stdio.h> > > /* This program implements a blindingly fast algorithm > to find prime numbers, using an elegant recursive method. */ > int _(int n, int m, int d, int t=0) > { > int r; > if (t) return d?1+_(n,m,d-1,d):n?_(n-1,m,m,n):0; > for(r=m!=n; d*(t<n); ++t) > r &= _(n,_(t,m,0,1),d-1)|!_(t,1,t); > return r*n; > } > > > /*------------------------------------------ > Print primes up to the requested value > --------------------------------------------*/ > int main(int argc, char* argv[]) > { > for(int n = 2; n <= 1000; n++) > printf("%d is%s prime\n",n, _(n,1,n,0)?"":" not"); > > return 0; > } > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
