Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- #define pLim 65536
- int a[pLim>>5];
- #define set(x) (a[x>>5] |= (1<<(x & 31)))
- #define unset(x) (a[x>>5] &= ~(1<<(x & 31)))
- bool isSet(int x)
- {
- if(a[x>>5] & (1 << (x & 31)))
- return true;
- return false;
- }
- void sieve()
- {
- int i, j;
- for(i = 2; i < pLim; i++)
- set(i);
- for(i = 2; i < pLim; i++)
- if(isSet(i))
- {
- for(j = i*i; j < pLim; j += i)
- unset(j);
- }
- /*for(i = 1; i < 32768; i++)
- if(isSet(i))
- cout << i << endl;*/
- }
- int main()
- {
- sieve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement