Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2018
2,514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <set>
  4. using namespace std;
  5. vector<int> d[2000005];
  6. set<int> s;
  7. bool p[2000005],er[2000005];
  8. int main()
  9. {
  10.     int n;
  11.     scanf("%d",&n);
  12.     for (int i=2;i<2000005;i++)
  13.     {
  14.         if (!p[i])
  15.         {
  16.             for (int x=i;x<2000005;x+=i)
  17.             {
  18.                 d[x].push_back(i);
  19.                 p[x]=1;
  20.             }
  21.         }
  22.         s.insert(i);
  23.     }
  24.     bool eq=1;
  25.     for (int i=0;i<n;i++)
  26.     {
  27.         int a;
  28.         scanf("%d",&a);
  29.         int cur=*s.begin();
  30.         if (eq)
  31.         {
  32.             cur=*s.lower_bound(a);
  33.             if (cur!=a)
  34.             eq=0;
  35.         }
  36.         printf("%d ",cur);
  37.         for (int x:d[cur])
  38.         {
  39.             for (int j=x;j<2000005;j+=x)
  40.             {
  41.                 if (!er[j])
  42.                 {
  43.                     s.erase(j);
  44.                     er[j]=1;
  45.                 }
  46.             }
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement