CF959D Mahmoud and Ehab and another array construction task [乱搞]

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值