Facebook
From Ngo Hoang Dung, 1 Month ago, written in C++.
Embed
Download Paste or View Raw
Hits: 133
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6.     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  7.     freopen("cloprime.inp","r",stdin);
  8.     freopen("cloprime.out","w",stdout);
  9.  bool kt[500005];
  10.  memset(kt,true,sizeof(kt));
  11.  kt[0]=kt[1]=false;
  12.  for(int i=2;i*i<=500005;i++)
  13.   if (kt[i])
  14.    for (int j=i*i;j<=500005;j+=i)
  15.     kt[j]=false;
  16.  int a,y;
  17.  cin>>a;
  18.  for (int i=1;i<=a;i++){
  19.   cin>>y;
  20.   while (!kt[y])
  21.    y--;
  22.   cout<<y<<endl;
  23.  }
  24.  return 0;
  25. }
  26.