RT,在luogu,c++98 AC而c++11/14 RE。考场已过大样例。 有dalao知道为什么吗?
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 10001000
bool p[N+10];
int s[N],tot,last[N];
bool check(int x){
bool flag=0;
while(x){
if(x%10==7) return 1;
x/=10;
}
return 0;
}
int find(int x){
// return (last[x]!=x) ? last[x]=find(last[x]) : x;zhan hui bao 1e6
int l=x;
while(last[x]!=x){
x=last[x];
}
while(last[l]!=l){
int t=l;
l=last[l];
last[t]=x;
}
return x;
}
int main(){
// freopen("number.in","r",stdin);
// freopen("number.out","w",stdout);
for(int i=1;i<=N;i++){
last[i]=i;
if(check(i)&&(!p[i])) {
for(int j=1;j*i<=N;j++){
p[i*j]=1;
}
}
if(p[i]||check(i)) s[++tot]=i,p[i]=1;
if(p[i-1]&&p[i]) last[i-1]=i;
}
int T;
cin>>T;
for(int i=1;i<=T;i++){
int k;
scanf("%d",&k);
if(p[k]) cout<<"-1\n";
else{
if(p[k+1]) printf("%d\n",find(k+1)+1);
else printf("%d\n",k+1);
}
}
// int l=0,m=0;
// for(int i=1;i<=N;i++){
// if(!p[i]) m=max(l,m),l=0;
// if(p[i]) l++;
// }
// cout<<m;
}
/*
1
6699998
*/