Indexed Permutations

Source file: kthperm.cc

You are to write a program that has to generate particular permutations of the first N nonegative integegers. Consider all of the permutations of the integers { 0, 1, 2, ..., N } to be ordered lexicographically, i.e., the order they would appear in a dictionary if  0 == a, 1 == b, 2 == c,  and so on. Thus, under this ordering and indexed from zero, the six permutations of the sequence { 0, 1, 2 } are

zeroth:   { 0, 1, 2 }
first:       { 0, 2, 1 }
second: { 1, 0, 2 }
third:      {1, 2, 0 }
fourth:    { 2, 0, 1 }
fifth:        { 2, 1, 0 }

Input

The input file consists of several pairs of nonnegative integers. The first, K, will be between 0 and 2^32-1 (a value that will fit in an unsigned long); the second, N, will be between 1 and 13, inclusive. It will always be the case that K is less than  N! .

Output

For each line in the input file, the output file should print the Kth permutation (under the lexicographic ordering above) of the sequence { 0, 1, ..., N-1 }. The sequence should be printed with a single space between each pair of integers and with no trailing spaces.

Sample Input

5 3
0 12
10 10
1000000000 13

Sample Output

2 1 0
0 1 2 3 4 5 6 7 8 9 10 11 12
0 1 2 3 4 5 7 9 6 8
2 1 0 8 10 7 9 12 4 6 11 3 5