問題一覧 > 通常問題

No.1311 Reverse Permutation Index

レベル : / AI推定難易度 : 825 / 実行時間制限 : 1ケース 1.500秒 / メモリ制限 : 256 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 105
作問者 : ciel / テスター : ngtkana
お気に入りにしたユーザー ProblemId : 887 / 自分の提出
問題文最終更新日: 2021-01-08 23:45:59
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
Advent Calendar Contest 2020 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。