This repository has been archived on 2024-08-23. You can view files and clone it, but cannot push or open issues or pull requests.
lessons/C++/lesson2/task6.cpp
2023-07-16 13:23:25 +00:00

28 lines
599 B
C++

#include <cmath>
#include <iostream>
#include <vector>
int main() {
int n;
std::cin >> n;
if (n < 0) {
std::cout << "You are a bad person!\n";
return 0;
}
std::vector<bool> values(n + 1, true);
int root = sqrt(n);
for (unsigned int i = 2; i <= root; i++) {
if (values[i]) {
std::cout << i << '\n';
for (int j = i * i; j <= n; j += i) {
values[j] = false;
}
}
}
for (int i = root + 1; i <= n; i++) {
if (values[i]) {
std::cout << i << '\n';
}
}
}