Advertisement
istinishat

seive

May 24th, 2017
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define MAX 1003
  5.  
  6. bool pr[MAX];
  7. vector<int>prime;
  8.  
  9. void seive()
  10. {
  11.     memset(pr,true,sizeof(pr));
  12.     pr[1]=pr[0]=false;
  13.     for(int i=2;i<MAX;i++){
  14.         if(!pr[i])
  15.             continue;
  16.         prime.push_back(i);
  17.         for(int j=i*2;j<MAX;j+=i)
  18.             pr[j]=false;
  19.     }
  20.  
  21. }
  22.  
  23. int main()
  24. {
  25.     int i,j;
  26.     seive();
  27.     cout<<prime.size()<<endl;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement