

Time Limit: 2 sec / Memory Limit: 256 MB
配点 : 点
問題文
黒板に 個の整数が書かれています。 番目の整数は です。
高橋君と青木君は以下の手順でこれらの数を一列に並べることにしました。
- 最初に、高橋君が好きな順に一列に並べる。
- 次に、青木君が隣り合う つの数を選んで入れ替えることを好きな回数だけ繰り返す。
ただし、入れ替える 数は互いに素でなければならない。
高橋君は最終的な並びが辞書順最小となるように、青木君は最終的な並びが辞書順最大となるように最適に行動するとしたとき、 最終的な数列を求めてください。
制約
入力
入力は以下の形式で標準入力から与えられる。
…
出力
最終的な数列を一行に出力せよ。
入力例 1Copy
5 1 2 3 4 5
出力例 1Copy
5 3 2 4 1
高橋君は与えられた数を という順番で並べれば、青木君が最適に動かしても となります。
入力例 2Copy
4 2 3 4 6
出力例 2Copy
2 4 6 3
Score : points
Problem Statement
There are integers written on a blackboard. The -th integer is .
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
Input
The input is given from Standard Input in the following format:
…
Output
Print the eventual sequence that will be produced, in a line.
Sample Input 1Copy
5 1 2 3 4 5
Sample Output 1Copy
5 3 2 4 1
If Takahashi arranges the given integers in the order , they will become after Aoki optimally manipulates them.
Sample Input 2Copy
4 2 3 4 6
Sample Output 2Copy
2 4 6 3