~/algor $ cat problems/kombinatorika-k-orin-almashtirish
k-th permutation
Medium
1000 ms
128 MB
56%
All $n!$ permutations of the numbers $1, 2, \dots, n$ are written out in lexicographic (dictionary) order: the first is $1\ 2 \dots n$, the last is $n\ \dots 2\ 1$. Print the $k$-th permutation of the list.
Input
One line with two positive integers: $n$ and $k$.
Output
$n$ space-separated numbers — the $k$-th permutation.
Note
$1 \le n \le 20$
$1 \le k \le n!$
Examples
Input #1
3 4
Output #1
2 3 1
Input #2
1 1
Output #2
1