文章
33
粉丝
78
获赞
3
访问
18.4k
#include <stdio.h>
#include <cstring>
#include <iostream>
using namespace std;
const int maxn = 1000000 + 5;
int prime[maxn];
void getprime(){
memset(prime,0,sizeof(prime));
for(int i = 2;i <=maxn;i++){
if(!prime[i]) prime[++prime[0]] = i;
for(int j = 1;j <=prime[0]&&prime[j] * i<=maxn;j++){
prime[prime[j] * i] = 1;
if(i % prime[j] == 0) break;
}
}
}
int main(){
getprime();
int n;
while(cin >> n){
int count = 0;
int num[maxn];
for(int i = 1;i<n;i++){
if(prime[i] <n&&prime[i]%10 ==1)
num[count++] = prime[i];
if(prime[i] >=n)
break;
}
if(count == 0) cout << "-1"<<endl;
else
for(int i = 0;i < count;i++)
cout <<num[i] <<" ";
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发