#SP0000229. Kiến tạo dãy nguyên tố cùng nhau của Mahmoud và Ehab (Mahmoud and Ehab and another array construction task)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Kiến tạo dãy nguyên tố cùng nhau của Mahmoud và Ehab (Mahmoud and Ehab and another array construction task)
Mahmoud and Ehab and another array construction task
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given an integer array , construct an array of equal length such that:
- is lexicographically greater than or equal to : if unequal, the first position at which they differ must have .
- Every .
- The elements are pairwise coprime: for every .
Among all valid arrays, output the lexicographically smallest one.
Input
The first line contains . The next line contains exactly integers .
Output
Print exactly space-separated integers forming the lexicographically smallest array that satisfies all three requirements.
Subtasks
-
Subtask 1 (20 points): ; for every .
-
Subtask 2 (30 points): ; for every .
-
Subtask 3 (50 points): ; for every .
Examples
Input
5
2 3 5 4 13
Output
2 3 5 7 11
Explanation
The prefix is already pairwise coprime, so it is kept. The next required value is at least , but uses prime already present. The smallest available integer not below is . At this point is strictly lexicographically larger than , so need not be at least ; the smallest unused prime is . The answer is .