洛谷上是对的
为什么在一本通网站(http://ybt.ssoier.cn:8088/problem_show.php?pid=2082)
就会超时啊???
求助
#include <iostream>
#include <cstring>
using namespace std;
const int N=1e7+100;
bool a[N];
int b[N];
void fin(int i){
int t=i;
while (t <= 1e7){
a[t]=true;
t+=i;
}
}
bool sol(int t){
while(t){
if(t%10 == 7) return true;
t/=10;
}
return false;
}
int main(){
ios::sync_with_stdio(false);
int lop=1;
for(int i=2 ; i<=1e7+1 ;++i){
if(!a[i]){
if(sol(i)) fin(i);
else{
b[lop]=i;
lop=i;
}
}
}
int t;
cin>>t;
while(t--){
int p;
cin>>p;
if(a[p]) cout<<"-1"<<endl;
else cout<<b[p]<<endl;
}
}