fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. const int N = 2e7;
  8.  
  9. vector <long long> is_prime(N, true);
  10. is_prime[0] = is_prime[1] = false;
  11.  
  12. vector <long long> primes;
  13.  
  14. for(long long i = 2; i < N; i++)
  15. {
  16. if(is_prime[i]) primes.push_back(i);
  17.  
  18. for(int j = 0; j < primes.size() && i*primes[j] < N; j++)
  19. {
  20. is_prime[i*primes[j]] = false;
  21.  
  22. if(i%primes[j] == 0) break;
  23. }
  24. }
  25.  
  26. cout << primes.size();
  27.  
  28. return 0;
  29. }
Success #stdin #stdout 0.26s 15232KB
stdin
Standard input is empty
stdout
1270607