代码:
#include<bits/stdc++.h>
using namespace std;
int i,j;
bool yijun[200005]={true};
int read(){
int s=0,w=1;
char c=getchar();
while(c<'0' || c>'9'){
if(c=='-')
w=-1;
c=getchar();
}
while(c>='0'&&c<='9'){
s=s*10+c-'0';
c=getchar();
}
return s*w;
}
bool shuo(int x){
if(x%7==0) return false;
while(x>=7){
if(x%10==7) return false;
x/=10;
}
return true;
}
void ter(){
for(i=7;i<=200001;i++){
if(!yijun[i]) continue;
if(!shuo(i)){
yijun[i]=false;
for(j=i;j<=200001;j+=i)
yijun[i]=false;
}
}
}
int main(){
ter();
int t,tt[200001]={0},ans[200001],sum=1;
cin>>t;
for(i=1;i<=t;i++)
ans[i]=read();
for(i=1;i<=t;i++){
if(!yijun[ans[i]]){
tt[sum]=-1;
sum++;
continue;
}
for(j=ans[i]+1;;j++)
if(yijun[j]){
tt[sum]=j;
sum++;
break;
}
}
for(i=1;i<=sum-1;i++)
cout<<tt[i]<<endl;
return 0;
}