Permutation Problem
InterviewTime limit2sMemory limit1024 MB
Given n and k, find the k-th permutation of 1 to n in lexicographic order in which the numbers 1 and 2 are not adjacent.
- Level
Medium5 of 10
- Topics
- Combinatorics, Backtracking
- Solved
- No attempts yet
Statement
A permutation of the numbers from 1 to is a sequence in which each of these numbers appears exactly once.
Permutation comes before permutation in lexicographic order if, for some , for all and .
Consider all permutations of the numbers from 1 to in which the numbers and are not in adjacent positions. Sort them in lexicographic order. Find the permutation that is -th in this order.
Input
The first line contains two positive integers and (, ). It is guaranteed that the permutation with this number exists.
Output
Print the answer to the problem.