fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define fi first
  4. #define se second
  5. #define ll long long
  6. #define all(x) (x).begin(), (x).end()
  7. #define MASK(i) (1LL<<(i))
  8. #define BIT(i,n) (((n)>>(i)) & 1LL)
  9.  
  10. template <class X, class Y> bool minimize(X& x, const Y& y) {
  11. if(x > y){ x = y; return 1; }
  12. return 0;
  13. }
  14.  
  15. template <class X, class Y> bool maximize(X& x, const Y& y) {
  16. if(x < y){ x = y; return 1; }
  17. return 0;
  18. }
  19.  
  20. const int N = 2e6 + 6;
  21.  
  22. int n, f[N];
  23.  
  24. void sieve()
  25. {
  26. f[0] = f[1] = 1;
  27. for(int i = 2; i * i < N; ++i){
  28. if(f[i]) continue;
  29. for(int j = i * i; j < N; j += i)
  30. f[j] = 1;
  31. }
  32.  
  33. for(int i = 2; i < N; ++i){
  34. if(!f[i]) f[i] = i;
  35. else f[i] = f[i - 1];
  36. }
  37. }
  38.  
  39. int main()
  40. {
  41. ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
  42. #define file "HAIUOC"
  43. if(fopen(file".inp","r")){
  44. freopen(file".inp","r",stdin);
  45. freopen(file".out","w",stdout);
  46. }
  47.  
  48. sieve();
  49. cin >> n;
  50. for(int i = 1, x; i <= n; ++i){
  51. cin >> x;
  52. cout << f[x] << " ";
  53. }
  54.  
  55. return 0;
  56. }
  57.  
Success #stdin #stdout 0.02s 11332KB
stdin
Standard input is empty
stdout
Standard output is empty