P26162 [AtCoder] [ARC047C] N!÷K-th Word
提高
题目描述

Problem Description

There are $ N $ types of characters in Takahashi language.

For convenience, we will assign each character an integer from $ 1 $ to $ N $ in lexicographical order.

All words in Takahashi language consist of $ N $ characters, and each of the $ N $ types of characters is included exactly once. Also, any string that satisfies this condition is a word in Takahashi language.

In other words, there are $ N! $ words in Takahashi language.

Given a positive integer $ K $ less than or equal to $ N $, find the $ N! ÷ K $-th word in lexicographical order among the words in Takahashi language.

Input Format

The input is given from the standard input in the following format:

$ N $ $ K $

  • The first line contains two integers $ N, K (1 ≦ K ≦ N ≦ 10^5) $ separated by a space.

Output Format

The output consists of $ N $ lines. The $ i $-th line should contain the integer corresponding to the $ i $-th character of the $ N! ÷ K $-th word in lexicographical order among the words in Takahashi language. End each output with a newline.

Sample Input and Output

Sample Input #1

4 3

Sample Output #1

2
1
4
3

Sample Input #2

11 7

Sample Output #2

2
7
9
5
4
11
10
8
6
3
1

Notes/Hints

Partial Points

This problem has partial points.

  • If you solve the dataset satisfying $ 1 ≦ N ≦ 20 $, you will be awarded $ 30 $ points.
  • If you solve the dataset satisfying $ 1 ≦ N ≦ 10^5 $, you will be awarded an additional $ 70 $ points. The total is $ 100 $ points.

Sample Explanation 1

Among the permutations of $ 1, 2, 3, 4 $, you need to output the $ 4! ÷ 3 = 8 $-th word in lexicographical order. Listing the first $ 8 $ words in lexicographical order, we get: $ 1, 2, 3, 4 $ $ 1, 2, 4, 3 $ $ 1, 3, 2, 4 $ $ 1, 3, 4, 2 $ $ 1, 4, 2, 3 $ $ 1, 4, 3, 2 $ $ 2, 1, 3, 4 $ $ 2, 1, 4, 3 $. Therefore, the word $ 2, 1, 4, 3 $ is the one we are looking for.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
4 3
样例输出
2 1 4 3