Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. #define pLim 65536
  4. int a[pLim>>5];
  5. #define set(x) (a[x>>5] |= (1<<(x & 31)))
  6. #define unset(x) (a[x>>5] &= ~(1<<(x & 31)))
  7. bool isSet(int x)
  8. {
  9. if(a[x>>5] & (1 << (x & 31)))
  10. return true;
  11. return false;
  12. }
  13. void sieve()
  14. {
  15. int i, j;
  16. for(i = 2; i < pLim; i++)
  17. set(i);
  18.  
  19. for(i = 2; i < pLim; i++)
  20. if(isSet(i))
  21. {
  22. for(j = i*i; j < pLim; j += i)
  23. unset(j);
  24. }
  25. /*for(i = 1; i < 32768; i++)
  26. if(isSet(i))
  27. cout << i << endl;*/
  28. }
  29. int main()
  30. {
  31. sieve();
  32. return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement