本地运行没问题……
#include<bits/stdc++.h>
using namespace std;
int T;
int x;
bool avi[10000502];
int nxt[10000502];
void init(int lim)
{
int lst,p;
for(int i=1;i<=lim-12;i++)
{
if(avi[i])//true 表示不合法
{
continue;
}
p=i;
bool f=true;
while(p)
{
if(p%10==7)
{
f=false;
break;
}
p/=10;
}
if(!f)
{
for(int j=i;j<=lim-12;j+=i)
{
avi[i]=true;
}
}else{
nxt[lst]=i;
lst=i;
}
}
}
int main()
{
// freopen("number4.in","r",stdin);
// freopen("number4.out","w",stdout);
init(10000200);
cin>>T;
while(T--)
{
scanf("%d",&x);
if(avi[x])
{
printf("-1\n");
}else{
printf("%d\n",nxt[x]);
}
}
return 0;
}
/*
10
99
94
6
69
44
95
36
3
96
26
*/