题解
2023-03-18 17:46:09
发布于:上海
37阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
const int N=1e7+5;
bool p[N];
int nxt[N];
int t,x,ls=1;
bool pd(int x){
while(x){
if(x%10==7) return 1;
x/=10;
}
return 0;
}
int main(){
cin>>t;
for(int i=2;i<=N;++i){
if(p[i]) continue;
if(pd(i)){
for(int j=i;j<=N;j+=i){
p[j]=1;
}
}
if(p[i]==0){
nxt[ls]=i;
ls=i;
}
}
//cout<<p[7]<<endl;
while(t--){
cin>>x;
if(p[x]){
printf("-1\n");
}else{
printf("%d\n",nxt[x]);
}
}
return 0;
}
这里空空如也
有帮助,赞一个