Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #define N 100000000/2/8+1
- using namespace std;
- char p[N];
- /// https://infogenius.ro/ciurul-lui-eratostene-cpp/
- int Ciur(int n)
- {
- int i,j,nr=1;
- for(i=1;((i*i)<<1)+(i<<1)<=n;i+=1)
- {
- if((p[i>>3]&(1<<(i&7)))==0)
- {
- for(j=((i*i)<<1)+(i<<1);(j<<1)+1<=n;j+=(i<<1)+1)
- {
- p[j>>3]|=(1<<(j&7));
- }
- }
- }
- for(i=1;2*i+1<=n;++i)
- if((p[i>>3]&(1<<(i&7)))==0)
- ++nr;
- return nr;
- }
- int main()
- {
- int n;
- cin>>n;
- cout<<Ciur(n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement