样例全部正确,洛谷爆零,求教
查看原帖
样例全部正确,洛谷爆零,求教
375195
闲着没事人楼主2021/11/23 08:44

代码如下:

#include <bits/stdc++.h>
using namespace std;
const int N = 1e7 + 10;

int t, p[N];

bool check(int x){
	if(x % 7 == 0) return true;
	while(x){
		if(x % 10 == 7) return true;
		x /= 10;
	}
	return false;
}

void get_p(){
	for(register int i = 1; i < N; i++){
		if(p[i]) continue;
		if(check(i)){
			for(register int j = 1; i * j < N; j++) p[i*j] = true;
		}
	}
}

int main(){
	ios::sync_with_stdio(false);
//	freopen("number.in", "r", stdin);
//	freopen("number.out", "w", stdout);

	cin >> t;
	get_p();
	
	while(t--){
		int n;
		cin >> n;
		if(p[n]) puts("-1");
		else cout << (find(p+n+1, p+N, 0) - p) << '\n';
	}
	
	return 0;
}
2021/11/23 08:44
加载中...