33 lines
742 B
C++
33 lines
742 B
C++
|
|
#include <bits/stdc++.h>
|
||
|
|
using namespace std;
|
||
|
|
set<int> s; // 幸运数集合
|
||
|
|
const int N = 1e6;
|
||
|
|
int main() {
|
||
|
|
int a, T;
|
||
|
|
cin >> a >> T;
|
||
|
|
|
||
|
|
// 筛法,枚举出1e6以下所有的超级幸运数
|
||
|
|
for (int i = 1; i * i <= N; i++)
|
||
|
|
if (i * i >= a) {
|
||
|
|
// 枚举超级幸运数的倍数
|
||
|
|
for (int j = 1; i * i * j <= N; j++)
|
||
|
|
s.insert(i * i * j);
|
||
|
|
}
|
||
|
|
|
||
|
|
while (T--) {
|
||
|
|
int x;
|
||
|
|
cin >> x;
|
||
|
|
// 判断x是不是超级幸运数或者幸运数
|
||
|
|
if (s.count(x))
|
||
|
|
cout << "Lucky" << endl;
|
||
|
|
else {
|
||
|
|
// 找出第一个比它大的幸运数
|
||
|
|
for (int i = x + 1;; i++)
|
||
|
|
if (s.count(i)) {
|
||
|
|
cout << i << endl;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return 0;
|
||
|
|
}
|