No.2449 square_permutation
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もしくは右上の雲マークをクリックしてアカウントを作成してください。
stoq