No.1311 Reverse Permutation Index
Problem Statement
3 1 4 2 5
This permutation can be multiplied by the permutation
2 4 1 3 5
to restore it to
1 2 3 4 5
, its original order.
Let us call this permutation the inverse permutation.
Now, among the permutations obtained by rearranging 1 2 3 4 5, 3 1 4 2 5 is number 50 in lexicographic order (updated at 00:55), and 2 4 1 3 5 is number 36 (where 1 2 3 4 5 is number 0). In this way, find the index of the inverse permutation of the N-th permutation.
Notes (no need to read these unless necessary)
The definition of a permutation is given at https://en.wikipedia.org/wiki/Permutation#One-line_notation
Input
N S
N: the index of the permutation
S: the length of the permutation
0 <= N < S! (< 264)
1 <= S <= 20
Output
Output the index of the inverse permutation on one line.
Print a newline at the end.
Sample
Sample 1
Input
50 5
Output
36
Sample 2
Input
1234567890123456789 20
Output
2375759657264653994
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
ngtkana