首页 技术 正文
技术 2022年11月16日
0 收藏 349 点赞 4,661 浏览 2317 个字

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;
}

  

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,497
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,910
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,744
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,498
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,136
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,300