D. Mahmoud and Ehab and another array construction task
time limit per test3 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
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
inputCopy
5
2 3 5 4 13
outputCopy
2 3 5 7 11
inputCopy
3
10 3 7
outputCopy
10 3 7
Note
Note that in the second sample, the array is already pairwise coprime so we printed it.
题意:给出一个序列a[n],求一个字典序最小的序列b[n]满足b[n]的字典序不小于a[n]的字典序并且所有的元素都互质(n<=1e5,ai<=1e5)
题解:记录一下每个数字x的最小质因子w(x),使用埃氏筛法即可,那么一个数字的质因子分解就可以转换成x==w(x)w(x/w(x))…,所以可以用这种方式快速把一个数字分解成若干质因子用于快速判断质因子是否被使用过以及标记质因子已经被使用过
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(x) cout<<#x<<" is "<<x<<endl;
const int maxn=3e6+5;
bool f[maxn];
ll tot,a[maxn],pri[maxn