AtCoder Grand Contest 010
翻译中…
Problem Statement
翻译中…
There are $N$ integers written on a blackboard. The $i$-th integer is $A_i$.
翻译中…
Takahashi and Aoki will arrange these integers in a row, as follows:
翻译中…
- First, Takahashi will arrange the integers as he wishes.
- Then, Aoki will repeatedly swap two adjacent integers that are coprime, as many times as he wishes.
翻译中…
We will assume that Takahashi acts optimally so that the eventual sequence will be lexicographically as small as possible, and we will also assume that Aoki acts optimally so that the eventual sequence will be lexicographically as large as possible. Find the eventual sequence that will be produced.
翻译中…
Constraints
翻译中…
$1 ≦ N ≦ 2000$$1 ≦ A_i ≦ 10^8$
翻译中…
Input
翻译中…
The input is given from Standard Input in the following format:
翻译中…
N
A_1 A_2 … A_N
翻译中…
Output
翻译中…
Print the eventual sequence that will be produced, in a line.
翻译中…
样例
Input #1
5
1 2 3 4 5
Output #1
5 3 2 4 1
If Takahashi arranges the given integers in the order $(1,2,3,4,5)$, they will become $(5,3,2,4,1)$ after Aoki optimally manipulates them.
Input #2
4
2 3 4 6
Output #2
2 4 6 3
题目信息
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。