Find kth Permutation

Given a set of 'n' elements, find their kth permutation.

Statement

Given two numbers nn and kk, find kth^{th} permutation of nn. For n=3n = 3, all permutations are (with ordering):

g array 1st 123 2nd 132 3rd 213 4th 231 5th 312 6th 321

Sample input

Here 4 is the number nn ...