Advertisement
smatskevich

Lesson3

Nov 26th, 2022
626
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.   int n; cin >> n;
  7.   bool* er = new bool[n]; // До n невключительно.
  8.   for (int i = 0; i < n; ++i) {
  9.     er[i] = true;
  10.   }
  11.   er[0] = false;
  12.   er[1] = false;
  13.   for (int x = 2; x < n; ++x) {
  14.     if (er[x]) {
  15.       for (int k = 2; k * x < n; ++k) {
  16.         er[k * x] = false;
  17.       }
  18.     }
  19.   }
  20.   for (int i = 0; i < n; ++i) {
  21.     if (er[i]) cout << i << " ";
  22.   }
  23.  
  24.   delete[] er;
  25.   return 0;
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement