70 分 恳求大佬优化
查看原帖
70 分 恳求大佬优化
353685
ACTREE楼主2022/10/3 10:41
#include<bits/stdc++.h>
using namespace std;
long long n,x,f[10000100],cnt;
int panduan1(long long x1){
	while(x1){
		if(x1%10==7){
			return 1;
		}
		x1/=10;
	}
	return 0;
}
void read(long long &x){
	x = 0;
	char c = getchar();
	bool w = 0;
	while(c < '0' || c > '9'){
		c = getchar();
	}
	while(c >= '0' && c <= '9'){
		x = x * 10 + c - '0';
		c = getchar();
	}
}
int main(){
    read(n);
    for(long long i=1;i<=10000100;i++){
    	if(panduan1(i)==1){
    		f[i]=1;
    		for(int j=i;j<=10000100;j+=i){
    			f[j]=1;
			}
		}
	}
	for(int i=1;i<=n;i++){
		read(x);
		if(f[x]==1){
			cout<<"-1"<<endl;
		}else{
			for(int j=x+1;j<=10000100;j++){
				if(f[j]!=1){
					cout<<j<<endl;
					break;
				}
			}
		}
	}
}
2022/10/3 10:41
加载中...