AcWing 3526. 素数
原题链接
简单
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int N = 1e4 + 100;
int t, n, m, k, l, r, op, x, y;
bool f[N];
int p[N];
bool flag;
void solve() {
k = sqrt(N);
f[1] = true;
for (int i = 2; i < k; i++) {
if (f[i])continue;
for (int j = i * i; j < N; j += i) {
f[j] = true;
}
}
for (int i = 1; i < N; i++) {
if (!f[i] && i % 10 == 1)p[++m] = i;
}
while (cin >> n) {
flag = false;
m = 1;
while (n > p[m]) {
flag = true;
cout << p[m++] << " ";
}
if (!flag) {
cout << "-1";
}
cout << "\n";
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}