Facebook
From tranhuumanh, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 135
  1. #include<bits/stdc++.h>
  2. #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  3. #define file freopen("CLOPRIME.inp","r",stdin);freopen("CLOPRIME.out","w",stdout);
  4. #define FOR(x,a,b) for (int x=a;x<=b;x++)
  5. #define FOD(x,a,b) for (int x=a;x>=b;x--)
  6. #define pub push_back
  7. #define pob pop_back
  8. #define ii  pair<int,int>
  9. #define pll pair<long long, long long>
  10. #define F first
  11. #define S second
  12. #define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
  13. typedef unsigned long long int ull;
  14. typedef long long ll;
  15. const long N=1e5 + 5;
  16. const int mod = 1e9 +7;
  17. using namespace std;
  18. int main()
  19. {
  20.  freopen("CLOPRIME.inp","r",stdin);
  21.  freopen("CLOPRIME.out","w",stdout);
  22.  ios_base::sync_with_stdio(false);
  23.  cin.tie(NULL);
  24.  cout.tie(NULL);
  25.  bool ktra[500005];
  26.  memset(ktra,true,sizeof(ktra));
  27.  ktra[0]=ktra[1]=false;
  28.  for(int i=2;i*i<=500005;i++)
  29.  {
  30.   if (ktra[i])
  31.    {
  32.    for (int j=i*i;j<=500005;j+=i)
  33.     {
  34.  ktra[j]=false;
  35.     }
  36.  }
  37.  }
  38.  int n,x;
  39.  cin>>n;
  40.  for (int i=1;i<=n;i++)
  41.  {
  42.   cin>>x;
  43.   while (!ktra[x])
  44.    x--;
  45.   cout<<x<<endl;
  46.  }
  47.  return 0;
  48. }