Advertisement
Guest User

Untitled

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