Advertisement
O_Egor

25

May 25th, 2022 (edited)
671
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4. #include <map>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.  
  10.     vector<char> prime(20001, true);
  11.     prime[0] = prime[1] = false;
  12.     for (int i = 2; i <= 20000; ++i)
  13.         if (prime[i])
  14.             if (i * 1ll * i <= 20000)
  15.                 for (int j = i * i; j <= 20000; j += i)
  16.                     prime[j] = false;
  17.  
  18.     int ans(0);
  19.     for (int i = 2; i < 20001; ++i)
  20.     {
  21.         if (prime[i])
  22.         {
  23.             ans++;
  24.         }
  25.     }
  26.     cout << ans;
  27.     return 0;
  28. }
Advertisement
RAW Paste Data Copied
Advertisement