1 solutions
-
1
#include<bits/stdc++.h> using namespace std; const int N=1001*1001+10; bool st[N]; int lucky[N]; int main() { int a,T; cin>>a>>T; for(int i=1;i<N;i++) { int t=sqrt(i); if(i>=a&&i==t*t) //幸运数的定义 { st[i]=true; //处理倍数 for(int j=i;j<N;j+=i) { st[j]=true; } } } //倒着处理这个数和这个数后面最接近的幸运数 for(int i=N-1;i>=1;i--) { if(st[i]) { lucky[i]=i; } else { lucky[i]=lucky[i+1]; } } while(T--) { int x; cin>>x; if(st[x]) cout<<"lucky"<<endl; else cout<<lucky[x]<<endl; } return 0; }
- 1
Information
- ID
- 2538
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 5
- Tags
- (None)
- # Submissions
- 6
- Accepted
- 3
- Uploaded By