文章
1
粉丝
88
获赞
0
访问
315
#include<bits/stdc++.h>
#include<algorithm>
#include<cmath>
using namespace std;
bool prime(int n) {
int flag = 0;
for (int i = 2; i < sqrt(n); i++) {
if ((n % i) == 0) {
return false;
flag = 1;
break;
}
}
if (flag == 0) return true;
}
int main() {
int n;
while (cin >> n) {
vector<int> a;
for (int i = 11; i < n; i += 10) {
if (prime(i)) a.push_back(i);
}
if (a.size() == 0) cout << "-1" << endl;
else {
for (int i = 0; i < a.size(); i++) {
if (i == a.size() - 1) cout << a[i] << endl;
else cout << a[i] << ' ';
}
}
}
return 0;
}
登录后发布评论
<=sqrt(n)