P7960 [NOIP2021]求助!!
  • 板块学术版
  • 楼主werwere
  • 当前回复5
  • 已保存回复6
  • 发布时间2024/8/29 00:01
  • 上次更新2024/8/29 11:30:38
查看原帖
P7960 [NOIP2021]求助!!
1071898
werwere楼主2024/8/29 00:01
#include<bits/stdc++.h>
using namespace std;
const int N=1e7+10;
bool f[N];
int ans[N];
bool check(int x) {
	while(x/=10) {
		if(x%10==7) {
			return true;
		}
	}
	return false;
}
void init() {
	int last=0;
	for(int i=1; i<=N-1; i++) {
		if (f[i]) {
			continue;
		}
		if (check(i)) {
			for (int j=1; i*j<=N-1; j++) {
				f[i*j]=1;
			}
			continue;
		}
		ans[last]=i;
		last=i;
	}
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	init();
	int t;
	cin>>t;
	while(t--) {
		int x;
		cin>>x;
		if(f[x]) {
			cout<<-1;
		} else {
			cout<<ans[x];
		}
		cout<<"\n";
	}
	return 0;
}
2024/8/29 00:01
加载中...