题解
2023-08-25 13:11:39
发布于:广东
14阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
const int N = 1e7 + 100;
int T, x, ls;
int f[N], nx[N];
bool check(int x)
{
while (x)
{
if (x % 10 == 7)
return 1;
x /= 10;
}
return 0;
}
void init()
{
for (int i = 1; i <= N - 10; i++)
{
if (f[i])
continue;
if (check(i))
{
for (int j = i; j <= N - 10; j += i)
f[j] = 1;
continue;
}
nx[ls] = i;
ls = i;
}
}
int main()
{
init();
cin>>T;
while (T--)
{
cin>>x;
if (f[x])
cout<<"-1\n";
else
cout<<nx[x]<<'\n';
}
return 0;
}
这里空空如也
有帮助,赞一个