Author: lllyouo
Date: 20250701
tag: 筛法拓展
link: https://www.luogu.com.cn/problem/P7960问题描述
分析
略
参考代码
cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e7 + 10;
bool v[N]; // true 表示不能报
int nxt[N], c;
bool check(int x) {
while (x != 0) {
if (x % 10 == 7) return true;
x /= 10;
}
return false;
}
int main() {
for (int i = 1; i < N; i++) {
if (v[i]) continue;
if (check(i)) {
for (int j = 1; j * i < N; j++) {
v[j * i] = 1; // 标记含 7 的数的倍数
}
continue;
}
nxt[c] = i;
c = i;
}
int T; cin >> T;
while (T--) {
int x; cin >> x;
if (v[x]) cout << -1 << endl;
else cout << nxt[x] << endl;
}
return 0;
}