蒟蒻70求条
查看原帖
蒟蒻70求条
1401250
Junsi楼主2024/11/27 20:36
#include<bits/stdc++.h>
using namespace std;
long long t,a;
string b;
int s[100000009];
inline long long p(long long x){
	if(s[x]==1)return 1;
	else if(s[x]==-1)return 0;
	if(x%7==0){s[x]=1;return 1;}
	long long y=x;
	while(y>=10){
	//	cout<<y<<endl;
		if(y%10==7){s[x]=1;return 1;}
		else y/=10;
	}
	if(y%10==7){s[x]=1;return 1;};
	//cout<<"///"<<endl;
	for(int i=2;i<=sqrt(x);i++){
		if(x%i==0){
			if(p(i)){s[x]=1;return 1;}
		//	cout<<i<<" "<<x/i<<endl;
			if(p(x/i)){s[x]=1;return 1;};
		}
	}
	s[x]=-1;
	return 0;
}
inline long long read(){
	b=getchar();
	if(b=="7")return 1;
	
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>t;
	while(t--){
		cin>>a;
		if(p(a)){cout<<-1<<endl;continue;}
		a++;
		while(p(a))a++;
		cout<<a<<endl;
	}
	//cout<<p(t);
	return 0;
}
2024/11/27 20:36
加载中...