#include <iostream>
#include <cstring>
using namespace std;
int book[100001];
int PRIME() {
for (int i = 2; i <= 100000; i++) {
if (book[i] == 0)
for (int j = i * 2; j <= 100000; j += i) {
book[j] = 1;
}
}
}
int main() {
int n;
cin >> n;
PRIME();
for (int i = 2; i <= n; i++) {
if (book[i] == 0)
cout << i << ' ';
}
return 0;
}
给出运行截图
试运行了下,没出现题主的错误。