文章
13
粉丝
76
获赞
5
访问
7.9k
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e4 + 1;
int prime[maxn];
int ans[maxn];
void getPrime(){
memset(prime, 0, sizeof(prime));
for(int i = 2; i <= maxn; i++){
if(0 == prime[i]){
prime[++prime[0]] = i;
}
for(int j = 1; j <= prime[0] && i * prime[j] <= maxn; j++){
prime[i * prime[j]] = 1;
if(0 == i % prime[j]){
break;
}
}
}
return;
}
int main(){
getPrime();
int n;
while(cin>>n){
int pos = 0;
for(int i = 1; i <= prime[0] && prime[i] < n; i++){
if(1 == prime[i] % 10){
ans[pos++] = prime[i];
}
}
if(0 == pos){
cout<<-1<<endl;
continue;
}
else{
cout<<ans[0];
for(int i = 1; i < pos; i++){
...
登录后发布评论
暂无评论,来抢沙发