Morass

Erathosieve

May 29th, 2016
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.36 KB | None | 0 0
  1. #define MX (1<<27)
  2. #define IS(A) ((cn[A>>6]>>(A&63))&1)
  3. #define ST(A) (cn[A>>6]|=1ULL<<((A&63)))
  4. ll P[MX>>1]={2},L(1),cn[1+(MX>>6)];
  5. void gen(){
  6.     ST(0),ST(1);
  7.     int Q(1+sqrt(MX));
  8. //    for(ll i(4);i<MX;i+=2)ST(i);
  9.     for(int k(3);k<=Q;k+=2)if(!IS(k))
  10.         for(ll h(k<<1),j(k*k);j<MX;j+=h)ST(j);
  11.     for(int i(3);i<MX;i+=2)if(!IS(i))P[L++]=i;
  12. }
Advertisement
Add Comment
Please, Sign In to add comment