D. Mahmoud and Ehab and another array construction task

Codeforces
IDCF959D
Time3000ms
Memory256MB
Difficulty
constructive algorithmsgreedymathnumber theory
English · Original
Chinese · Translation
Formal · Original
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_. * _b__i_ ≥ 2. * _b_ is pairwise coprime: for every 1 ≤ _i_ < _j_ ≤ _n_, _b__i_ and _b__j_ are coprime, i. e. _GCD_(_b__i_, _b__j_) = 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 _x__i_ > _y__i_ and _x__j_ = _y__j_ for all 1 ≤ _j_ < _i_. An array _x_ is equal to an array _y_ if _x__i_ = _y__i_ 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 _a_1, _a_2, ..., _a__n_ (2 ≤ _a__i_ ≤ 105), the elements of _a_. ## Output Output _n_ space-separated integers, the _i_\-th of them representing _b__i_. [samples] ## Note Note that in the second sample, the array is already pairwise coprime so we printed it.
Mahmoud 有一个由 #cf_span[n] 个整数组成的数组 #cf_span[a]。他要求 Ehab 找到另一个 *长度相同* 的数组 #cf_span[b],使得: Ehab 想要选择一个特殊的数组,因此他希望在所有可能的变体中找到字典序最小的数组。你能找到它吗? 数组 #cf_span[x] 被称为字典序大于数组 #cf_span[y],如果存在一个下标 #cf_span[i],使得 #cf_span[xi > yi] 且对所有 #cf_span[1 ≤ j < i] 都有 #cf_span[xj = yj]。数组 #cf_span[x] 等于数组 #cf_span[y],当且仅当对所有 #cf_span[1 ≤ i ≤ n] 都有 #cf_span[xi = yi]。 第一行包含一个整数 #cf_span[n] #cf_span[(1 ≤ n ≤ 105)],表示数组 #cf_span[a] 和 #cf_span[b] 的元素个数。 第二行包含 #cf_span[n] 个整数 #cf_span[a1], #cf_span[a2], #cf_span[...], #cf_span[an] #cf_span[(2 ≤ ai ≤ 105)],表示数组 #cf_span[a] 的元素。 请输出 #cf_span[n] 个用空格分隔的整数,第 #cf_span[i] 个整数表示 #cf_span[bi]。 注意,在第二个测试用例中,数组已经两两互质,因此直接输出原数组。 ## Input 第一行包含一个整数 #cf_span[n] #cf_span[(1 ≤ n ≤ 105)],表示数组 #cf_span[a] 和 #cf_span[b] 的元素个数。第二行包含 #cf_span[n] 个整数 #cf_span[a1], #cf_span[a2], #cf_span[...], #cf_span[an] #cf_span[(2 ≤ ai ≤ 105)],表示数组 #cf_span[a] 的元素。 ## Output 请输出 #cf_span[n] 个用空格分隔的整数,第 #cf_span[i] 个整数表示 #cf_span[bi]。 [samples] ## Note 注意,在第二个测试用例中,数组已经两两互质,因此直接输出原数组。
**Definitions** Let $ n \in \mathbb{Z} $ be the length of the arrays. Let $ A = (a_1, a_2, \dots, a_n) $ be the given array of integers, where $ a_i \in \mathbb{Z} $ and $ 2 \leq a_i \leq 10^5 $. Let $ B = (b_1, b_2, \dots, b_n) $ be the target array of integers, with $ b_i \geq 1 $, satisfying: - $ \gcd(b_i, b_j) = 1 $ for all $ 1 \leq i < j \leq n $ (pairwise coprime), - $ b_i \geq a_i $ for all $ i \in \{1, \dots, n\} $. **Constraints** 1. $ 1 \leq n \leq 10^5 $ 2. $ 2 \leq a_i \leq 10^5 $ for all $ i \in \{1, \dots, n\} $ **Objective** Find the lexicographically minimal array $ B = (b_1, \dots, b_n) $ satisfying the above constraints.
Samples
Input #1
5
2 3 5 4 13
Output #1
2 3 5 7 11
Input #2
3
10 3 7
Output #2
10 3 7
API Response (JSON)
{
  "problem": {
    "name": "D. Mahmoud and Ehab and another array construction task",
    "description": {
      "content": "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_. *   _b__i_ ≥ ",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 3000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF959D"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Mahmoud has an array _a_ consisting of _n_ integers. He asked Ehab to find another array _b_ **of the same length** such that:\n\n*   _b_ is lexicographically greater than or equal to _a_.\n*   _b__i_ ≥ ...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "Mahmoud 有一个由 #cf_span[n] 个整数组成的数组 #cf_span[a]。他要求 Ehab 找到另一个 *长度相同* 的数组 #cf_span[b],使得:\n\nEhab 想要选择一个特殊的数组,因此他希望在所有可能的变体中找到字典序最小的数组。你能找到它吗?\n\n数组 #cf_span[x] 被称为字典序大于数组 #cf_span[y],如果存在一个下标 #cf_span[i],使...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z} $ be the length of the arrays.  \nLet $ A = (a_1, a_2, \\dots, a_n) $ be the given array of integers, where $ a_i \\in \\mathbb{Z} $ and $ 2 \\leq a_i \\leq 10^5 $. ...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments