SHARE
TWEET

Untitled

GastonFontenla Nov 19th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int LIM = 10000000;
  6. bool esPrimo[LIM+1];
  7.  
  8. vector <int> criba()
  9. {
  10.     esPrimo[2] = true;
  11.     for(int i=3; i<=LIM; i+=2)
  12.         esPrimo[i] = true;
  13.  
  14.     for(int i=3; i*i <= LIM; i++)
  15.         if(esPrimo[i])
  16.             for(int j=i*2; j<=LIM; j+=i)
  17.                 esPrimo[j] = false;
  18.  
  19.     vector <int> primos;
  20.     for(int i=2; i<=LIM; i++)
  21.         if(esPrimo[i])
  22.             primos.push_back(i);
  23.  
  24.     return primos;
  25. }
  26.  
  27. int main()
  28. {
  29.     auto p = criba();
  30.  
  31.     cout << p.size() << endl;
  32.  
  33.  
  34.     return 0;
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top