Mahmoud has an array a consisting of n integers. He asked Ehab to find another array b 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 ≤ n, bi 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 i such 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 and b.

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

Output

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

Examples
Input

Copy
5
2 3 5 4 13
Output

Copy
2 3 5 7 11 
Input

Copy
3
10 3 7
Output

Copy
10 3 7 
Note

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

求一个互素的序列且字典序比 A 序列大的最小序列;

显然,当某一位置的 b[ i ]> a[ i ] 时,我们只需要安排剩下的数使得 b 数列互素即可;

那么这个我们可以用 fg 来标记一下;

如何保证我们的序列互素呢?考虑质因子,

我们用 use 来看最小质因子是否有使用,如果已经使用,那么显然不能选用;

#include<bits/stdc++.h>
using namespace std; #define maxn 200005 int prime[2000004],pre[2000004];
int n;
int a[maxn];
int b[maxn];
bool fg,vis[2000004],use[2000005]; bool judge(int x)
{
// 检验 x 是否有已经用过的质因子
int num[60],cnt=0;
while(vis[x]){
num[++cnt]=pre[x];x/=pre[x];
}
num[++cnt]=x;
for(int i=1;i<=cnt;i++){
if(use[num[i]])return false;
}
return true;
} int main()
{
ios::sync_with_stdio(0);
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
int cnt=0;
for(int i=2;i<=2000000;i++){
if(!vis[i]){
prime[++cnt]=i;
}
for(int j=1;j<=cnt;j++){
int tmp=i*prime[j];
if(tmp>2000000)break;
vis[tmp]=1;
pre[tmp]=prime[j];// 最小质因子
if(i%prime[j]==0)break;
}
}
int j=1;
for(int i=1;i<=n;i++){
if(fg){
while(use[prime[j]])j++;
b[i]=prime[j];
use[prime[j]]=1;
}
else{
int tmp=a[i];
while(!judge(tmp))tmp++;
if(tmp>a[i])fg=1;
b[i]=tmp;
while(vis[tmp]){
use[pre[tmp]]=1;tmp/=pre[tmp];
}
use[tmp]=1;
}
}
for(int i=1;i<=n;i++)cout<<b[i]<<' ';
cout<<endl;
}

CF959D Mahmoud and Ehab and another array construction task 数学的更多相关文章

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

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

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

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

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

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

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

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

  5. Codeforces 959 D Mahmoud and Ehab and another array construction task

    Discription Mahmoud has an array a consisting of n integers. He asked Ehab to find another arrayb of ...

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

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

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

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

  8. 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的子序列 ...

  9. [CF959F]Mahmoud and Ehab and yet another xor task题解

    搞n个线性基,然后每次在上一次的基础上插入读入的数,前缀和线性基,或者说珂持久化线性基. 然后一个num数组记录当时线性基里有多少数 然后每次前缀操作一下就珂以了 代码 #include <cs ...

随机推荐

  1. Ubuntu 下 ROS Kinetic 的安装

    安装环境为 Ubuntu 16.04 配置 Ubuntu 软件仓库 打开“设置”中的“软件和更新” 把 “restricted”.“universe” 和 “multiverse” 这三项勾上 勾完后 ...

  2. leetcode429

    这道题目是属于树的层次遍历,使用两层的队列非空判断. class Solution { public: vector<vector<int>> levelOrder(Node* ...

  3. 配置mysql 问题解决

    问题 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--s ...

  4. java获取多个汉字的拼音首字母

    本文属于http://java.chinaitlab.com/base/803353.html原创!!! public class PinYin2Abbreviation { // 简体中文的编码范围 ...

  5. spirng boot web配置开发

    spring-booter-starter-web是spring-boot web发开的核心,自动配置信息存储在spring-boot-autoconfigure.jar 下面的web目录里面,包含了 ...

  6. nodejs安装配置

    1.安装node.js(6.3.0)2.检测PATH环境变量是否配置了Node.jscmd下node --version3.D:/www/nodejs文件夹下创建hello.jsvar http = ...

  7. docker学习(2)基本命令

    原文地址:http://blog.csdn.net/we_shell/article/details/38368137 1. 查看docker信息(version.info) # 查看docker版本 ...

  8. PCL—关键点检测(NARF)低层次点云处理

    博客转载自:http://www.cnblogs.com/ironstark/p/5051533.html 关键点检测本质上来说,并不是一个独立的部分,它往往和特征描述联系在一起,再将特征描述和识别. ...

  9. ZROI2018提高day4t3

    传送门 分析 我们假设如果一个点是0则它的值为-1,如果一个点是1则值为1,则一个区间的答案便是max(pre[i]+sur[i]),这里的pre[i]表示此区间i点和它之前的的前缀的最大值,sur[ ...

  10. Luogu 4323 [JSOI2016]独特的树叶

    新技能get 树哈希,考虑到两棵树相同的条件,把每一个结点的哈希值和树的siz写进哈希值里去. 做出A树每一个结点为根时的树的哈希值丢进set中,然后暴力枚举B树中度数为1的点,求出删掉这个点之后的哈 ...