1 solutions
-
0
C++ :
#include <bits/stdc++.h> using namespace std; bool vis[1100000]; int main() { int a, n; cin >> a >> n; vector<int> ans; // 存储幸运数字 // 能得出当x=1000001 最差的幸运数为1002001,1002001为完全平方数 for (int i = ceil(sqrt(a)); i <= 1001; i++) { int x = i * i; // x为完全平方数 for (int j = 1; j * x <= 1002001; j++) { if (!vis[x * j]) //超级幸运数的倍数 { ans.push_back(x * j); vis[x * j] = true; } } } sort(ans.begin() , ans.end()); while (n--) { int x; cin >> x; if (vis[x]) cout << "lucky" << endl; else { int pos = upper_bound(ans.begin(), ans.end(), x) - ans.begin(); cout << ans[pos] << endl; } } return 0; }
- 1
Information
- ID
- 101
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By