Facebook
From Lê Hải Đăng, 1 Month ago, written in C++.
This paste is a reply to COUNTNUM from Lê Hải Đăng - view diff
Embed
Download Paste or View Raw
Hits: 134
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. long long t,n;
  5. int x[1000011];
  6.  
  7. void sieve(int N) {
  8.     for(int i=0;i<=N;++i)x[i]=1;
  9.     x[0]=0;
  10.     x[1]=0;
  11.     for(int i=2;i*i<=N;++i)
  12.         if(x[i]==1) for(int j=i*i;j<=N;j+=i)x[j]=0;
  13. }
  14. int main()
  15. {
  16.     freopen("CLOPRIME.inp","r",stdin);
  17.     freopen("CLOPRIME.out","w",stdout);
  18.     sieve(1000010);
  19.     cin>>t;
  20.     while(t--){
  21.         cin>>n;
  22.         while(x[n]==0)n--;
  23.         cout<<n<<endl;
  24.     }
  25. }