#K88792. K-th Permutation Sequence

    ID: 37387 Type: Default 1000ms 256MiB

K-th Permutation Sequence

K-th Permutation Sequence

Given two integers \(n\) and \(k\), where \(1 \le n \le 9\) and \(1 \le k \le n!\), find the \(k\)-th permutation of the sequence \([1, 2, \ldots, n]\) in lexicographical order.

The permutation sequence is defined as all possible arrangements of the numbers from 1 to \(n\) when sorted in ascending lexicographical order. For example, for \(n = 3\), the lexicographical permutations are:

  • 1 2 3
  • 1 3 2
  • 2 1 3
  • 2 3 1
  • 3 1 2
  • 3 2 1

Your task is to compute the permutation corresponding to the given \(k\). Use \(k - 1\) as a zero-based index when calculating the permutation.

inputFormat

The input consists of a single line with two space-separated integers \(n\) and \(k\), where \(n\) represents the number of elements and \(k\) the 1-indexed position of the desired permutation in the lexicographical order.

outputFormat

Output the \(k\)-th permutation as a sequence of \(n\) space-separated integers in a single line.

## sample
3 3
2 1 3