代码如下:
#include <bits/stdc++.h>
using namespace std;
const int N = 1e7 + 10;
int t, p[N];
bool check(int x){
if(x % 7 == 0) return true;
while(x){
if(x % 10 == 7) return true;
x /= 10;
}
return false;
}
void get_p(){
for(register int i = 1; i < N; i++){
if(p[i]) continue;
if(check(i)){
for(register int j = 1; i * j < N; j++) p[i*j] = true;
}
}
}
int main(){
ios::sync_with_stdio(false);
cin >> t;
get_p();
while(t--){
int n;
cin >> n;
if(p[n]) puts("-1");
else cout << (find(p+n+1, p+N, 0) - p) << '\n';
}
return 0;
}