Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- vector<int> d[2000005];
- bool p[2000005],used[2000005];
- bool ok(int x)
- {
- bool ret=1;
- for (int i:d[x])
- ret&=!used[i];
- return ret;
- }
- int main()
- {
- int n;
- scanf("%d",&n);
- for (int i=2;i<2000005;i++)
- {
- if (!p[i])
- {
- for (int x=i;x<2000005;x+=i)
- {
- d[x].push_back(i);
- p[x]=1;
- }
- }
- }
- bool eq=1;
- int cur=2;
- for (int i=0;i<n;i++)
- {
- int a;
- scanf("%d",&a);
- int out=a;
- if (eq)
- {
- while (!ok(out))
- out++;
- if (out!=a)
- eq=0;
- }
- else
- {
- while (!ok(cur))
- cur++;
- out=cur;
- }
- printf("%d ",out);
- for (int x:d[out])
- used[x]=1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement