問題一覧 > 通常問題

No.2449 square_permutation

レベル : / AI推定難易度 : 1100 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 36
作問者 : hiryuN / テスター : stoq
お気に入りにしたユーザー ProblemId : 9284 / 自分の提出
問題文最終更新日: 2023-10-05 19:14:08
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original

Problem Statement

You are given a positive integer $N$. Among the permutations $P$ of $(1, 2, ..., N)$ satisfying the following condition, output the lexicographically largest one.

  • For every $i$ satisfying $1 \leq i \leq N$, $P_i \times i$ is a perfect square.

It can be proved that, under the given constraints, at least $1$ permutation satisfying the condition exists.

Input

$N$

  • $1 \leq N \leq 3×10^5$
  • $N$ is a positive integer

Output

Output the lexicographically largest permutation $P$ satisfying the condition, separated by spaces.

Sample

Sample 1
Input
3
Output
1 2 3

1 2 3 is the only permutation satisfying the condition, so output it.

Sample 2
Input
6
Output
4 2 3 1 5 6

There are $2$ permutations satisfying the condition, 1 2 3 4 5 6 and 4 2 3 1 5 6, so output the latter, which is lexicographically larger.

Sample 3
Input
20
Output
16 18 12 9 20 6 7 8 4 10 11 3 13 14 15 1 17 2 19 5

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。