数据下载后全过,全 TLE求助(悬一关)
查看原帖
数据下载后全过,全 TLE求助(悬一关)
757869
hysbzdkf楼主2024/5/21 21:29

RT,代码如下:

#include<bits/stdc++.h>
using namespace std;
const int MAXN=10000001;
int T,n,ne[MAXN+1];
bool flag[MAXN+1];
bool check(int x){
	while(x){
		if(x%10==7)
			return 1;
		x/=10;
	}
}
void shai(){
	for(int i=1;i<=MAXN;i++){
		if(flag[i])
			continue;
		if(check(i)){
			for(int j=1;i*j<=MAXN;j++)
				flag[i*j]=1;
		}
	}
}
int main(){
	shai();
	int la=0;
	for(int i=1;i<=MAXN;i++){
		if(flag[i])
			continue;
		for(int j=la;j<i;j++)
			ne[j]=i;
		la=i;
	}
	cin>>T;	
	while(T--){
		cin>>n;
		if(flag[n])
			cout<<-1<<endl;
		else{
			cout<<ne[n]<<endl;
		}
	}
	return 0;
}

/*




*/
2024/5/21 21:29
加载中...