4 solutions
-
0
#include <bits/stdc++.h> using namespace std; const int M = 1000002; bool sq[M] = {0}; bool luck[M] = {0}; int nxt[M] = {0}; int main() { ios::sync_with_stdio(0); cin.tie(0); int a, n; cin >> a >> n; for(int i=1; i*i<M; i++) { if(i*i >= a) sq[i*i] = true; } for(int i=a; i<M; i++) { if(sq[i]) { for(int j=i; j<M; j+=i) { luck[j] = true; } } } int last = M; for(int i=M-1; i>=1; i--) { if(luck[i]) last = i; nxt[i] = last; } while(n--) { int x; cin >> x; if(luck[x]) cout << "lucky\n"; else cout << nxt[x] << "\n"; } return 0; }
Information
- ID
- 4945
- Time
- 1000ms
- Memory
- 512MiB
- Difficulty
- 5
- Tags
- # Submissions
- 42
- Accepted
- 12
- Uploaded By