Facebook
From Nguyễn Tiến Anh, 1 Month ago, written in C++.
This paste is a reply to cloprime from Nguyễn Tiến Anh - view diff
Embed
Download Paste or View Raw
Hits: 151
  1.     #include <bits/stdc++.h>
  2.     typedef long long ll;
  3.     #define FOR(i,l,r) for (int i=l;i<=r;i++)
  4.     #define FOD(i,r,l) for (int i=r;i>=l;i--)
  5.     #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  6.  
  7.     using namespace std;
  8.     const int N = 1e6+5;
  9.     bool Pr[N+1];
  10.     void sang() {
  11.         for(int i = 0; i <= N;++i) {
  12.             Pr[i] = true;
  13.         }
  14.         Pr[0] = false;
  15.         Pr[1] = false;
  16.         for(int i = 2; i * i <= N; ++i) {
  17.              if(Pr[i] == true) {
  18.                  for(int j = i * i; j <= N; j += i)
  19.                      Pr[j] = false;
  20.             }
  21.         }
  22.     }
  23.     int main()
  24.     {
  25.         freopen("cloprime.inp","r",stdin);
  26.         freopen("cloprime.out","w",stdout);
  27.         fast;
  28.         int n; cin>>n;
  29.         sang();
  30.         for(int i=1;i<=n;i++)
  31.         {
  32.             int x; cin>>x;
  33.             while(!Pr[x])
  34.                 x--;
  35.             cout<<x<<endl;
  36.         }
  37.     }
  38.  
  39.