1461 第m个排列


Submit solution

Points: 100
Time limit: 1.0s
Memory limit: 32M

Problem types
Allowed languages
C, C++, Java, Python

Description

1—n的排列共有n!种,把这n!种排列按字典序顺序排列。比如n=3时,所有的排列是 123,132,213,231,312,321.现在告诉你n(n=1)和m(m=1,n<10,m<=n!),代表一组输入数据,n==0,m==0表示输入结束。

Output

对于每一组数据,输出1—n的排列中的第m个排列。

Sample

Input

1 1
2 2
3 2
4 5
8 123
0 0

Output

1
21
132
1423
12435768

Comments

There are no comments at the moment.