Discription

Mahmoud has an array a consisting of n integers. He asked Ehab to find another arrayb of the same length such that:

  • b is lexicographically greater than or equal to a.
  • bi ≥ 2.
  • b is pairwise coprime: for every 1 ≤ i < j ≤ nbi and bj are coprime, i. e.GCD(bi, bj) = 1, where GCD(w, z) is the greatest common divisor of w and z.

Ehab wants to choose a special array so he wants the lexicographically minimal array between all the variants. Can you find it?

An array x is lexicographically greater than an array y if there exists an index isuch than xi > yi and xj = yj for all 1 ≤ j < i. An array x is equal to an array y if xi = yi for all 1 ≤ i ≤ n.

Input

The first line contains an integer n (1 ≤ n ≤ 105), the number of elements in a andb.

The second line contains n integers a1a2, ..., an (2 ≤ ai ≤ 105), the elements of a.

Output

Output n space-separated integers, the i-th of them representing bi.

Examples

Input
5
2 3 5 4 13
Output
2 3 5 7 11 
Input
3
10 3 7
Output
10 3 7 

Note

Note that in the second sample, the array is already pairwise coprime so we printed it.

字典序显然可以贪心,如果前若干位都和a一样的话,那么我们就找>=a[now] 的可以选的最小的数;否则就直接选现在可以取的最小的数。

然后我们每次选了一个数之和都要把有和这个数至少一个质因子相同的数给删掉,介于一个质因子只会被删一次,所以复杂度还是可靠的。。。

至于数最大处理到多少。。。。我一开始选的10^6然后正好RE了,,换成2*10^6就A 了 。。。。迷

主要是这个选小了会WA,选大了怕T。。。要是考试的时候就取一个最大的不会T的值吧2333.

#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
const int maxn=2000000;
const int inf=1e9;
vector<int> D[maxn+5];
int MIN[maxn*4+5],n;
int le,ri,now,num;
bool v[maxn+5],F=0; inline void maintain(int o,int lc,int rc){
MIN[o]=min(MIN[lc],MIN[rc]);
} void build(int o,int l,int r){
if(l==r){ MIN[o]=l; return;}
int mid=l+r>>1,lc=o<<1,rc=(o<<1)|1;
build(lc,l,mid),build(rc,mid+1,r);
maintain(o,lc,rc);
} inline void init(){
for(int i=2;i<=maxn;i++) if(!v[i])
for(int j=i;j<=maxn;j+=i) v[j]=1,D[j].pb(i);
build(1,1,maxn),memset(v,0,sizeof(v));
} void update(int o,int l,int r){
if(l==r){ MIN[o]=inf; return;}
int mid=l+r>>1,lc=o<<1,rc=(o<<1)|1;
if(le<=mid) update(lc,l,mid);
else update(rc,mid+1,r);
maintain(o,lc,rc);
} void query(int o,int l,int r){
if(l>=le&&r<=ri){ num=min(num,MIN[o]); return;}
int mid=l+r>>1,lc=o<<1,rc=(o<<1)|1;
if(le<=mid) query(lc,l,mid);
if(ri>mid) query(rc,mid+1,r);
} inline void MDF(int x){
for(le=x;le<=maxn;le+=x) if(!v[le]) v[le]=1,update(1,1,maxn);
} inline void solve(){
le=F?2:now,num=inf,ri=maxn,query(1,1,maxn);
printf("%d ",num);
if(num>now) F=1;
for(int i=D[num].size()-1;i>=0;i--) MDF(D[num][i]);
} int main(){
init(),scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&now);
solve();
}
return 0;
}

  

Codeforces 959 D Mahmoud and Ehab and another array construction task的更多相关文章

  1. Codeforces 959D. Mahmoud and Ehab and another array construction task(构造, 简单数论)

    Codeforces 959D. Mahmoud and Ehab and another array construction task 题意 构造一个任意两个数都互质的序列,使其字典序大等于a序列 ...

  2. codeforces-473D Mahmoud and Ehab and another array construction task (素数筛法+贪心)

    题目传送门 题目大意:先提供一个数组,让你造一个数组,这个数组的要求是 1 各元素之间都互质  2  字典序大于等于原数组  3 每一个元素都大于2 思路: 1.两个数互质的意思就是没有公因子.所以每 ...

  3. D. Mahmoud and Ehab and another array construction task 因子分界模板+贪心+数学

    D. Mahmoud and Ehab and another array construction task 因子分解模板 题意 给出一个原序列a 找出一个字典序大于a的序列b,使得任意 \(i!= ...

  4. Codeforces 959 F. Mahmoud and Ehab and yet another xor task

    \(>Codeforces\space959 F. Mahmoud\ and\ Ehab\ and\ yet\ another\ xor\ task<\) 题目大意 : 给出一个长度为 \ ...

  5. CF959D Mahmoud and Ehab and another array construction task 数学

    Mahmoud has an array a consisting of n integers. He asked Ehab to find another array b of the same l ...

  6. [CF959D]Mahmoud and Ehab and another array construction task题解

    解法 非常暴力的模拟. 一开始吧\(1 -> 2 \times 10^6\)全部扔进一个set里,如果之前取得数都是与原数组相同的,那么lower_bound一下找到set中大于等于它的数,否则 ...

  7. Codeforces 959 E Mahmoud and Ehab and the xor-MST

    Discription Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him ...

  8. Codeforces 959F Mahmoud and Ehab and yet another xor task 线性基 (看题解)

    Mahmoud and Ehab and yet another xor task 存在的元素的方案数都是一样的, 啊, 我好菜啊. 离线之后用线性基取check存不存在,然后计算答案. #inclu ...

  9. 959F - Mahmoud and Ehab and yet another xor task xor+dp(递推形)+离线

    959F - Mahmoud and Ehab and yet another xor task xor+dp+离线 题意 给出 n个值和q个询问,询问l,x,表示前l个数字子序列的异或和为x的子序列 ...

随机推荐

  1. glove 安装错误

    https://stackoverflow.com/questions/44921611/error-installing-glove-python-link-exe-failed-with-exit ...

  2. Spring框架xml配置文件 复杂类型属性注入——数组 list map properties DI dependency injection 依赖注入——属性值的注入依赖于建立的对象(堆空间)

    Person类中的各种属性写法如下: package com.swift.person; import java.util.Arrays; import java.util.List; import ...

  3. iOS开发遇到的坑之四--图片命名不规范

    最近上手并主导一个小项目的研发,在开发地图模块的时候,UI切图给我们使用,他给的图片命名是1.1.1.png 1.1.2.png 1.1.3.png 我也没有多看,就直接打包发给小组成员叫他添加到Im ...

  4. Python内置方法详解

    1. 字符串内置方法详解 为何要有字符串?相对于元组.列表等,对于唯一类型的定义,字符串具有最简单的形式. 字符串往往以变量接收,变量名. 可以查看所有的字符串的内置方法,如: 1> count ...

  5. 【css】清楚浏览器端缓存

    /css/common.css?version=1.0.7   在css链接后面加个参数版本号控制,刷新浏览器缓存

  6. (转)UITextField

    //初始化textfield并设置位置及大小 UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(20, 20, 130, ...

  7. 与LCD_BPP相关的函数

    board/freescale/mx6q_sabresd/mx6q_sabresd.c:    panel_info.vl_bpix = LCD_BPP; common/lcd.c:   off  = ...

  8. 代理授权验证_web客户端授权验证

    HTTPPasswordMgrWithDefaultRealm() HTTPPasswordMgrWithDefaultRealm()类将创建一个密码管理对象,用来保存 HTTP 请求相关的用户名和密 ...

  9. addEvenListener('DOMContentLoaded',function(){})

  10. vmware 装 puppy

    说做就做了,但是开始怎么试都没装成功,后来在网上查了些资料,再结合自己的实践,终于成功了.下面我就把如何让Puppy Linux安装到VMware 硬盘上一步一步奉献给大家. 一.准备 1.1 安装好 ...