The survey of permutations of finite sets is an important subject in the fields of combinatorics and group theory. In elementary combinatorics, the K-permutations, or partial permutations, are the ordered agreements of K distinct components choose from a set. Stedman widens the consideration of permutations; he goes on to consider the number of permutations of the letters of the alphabet and of horses from a stable of 20.A first case in which apparently unrelated mathematical questions were study with the help of permutations happened around 1770, when Joseph Louis Lagrange, in the survey of polynomial equations, detected that property of the permutations of the beginnings of an equation are associated to the possibility to solve it. Fabian Stedman in 1677 described factorials when explaining the number of permutations of Bell in change ringing. The rule to determine the number of permutations of n objects was known in Indian culture around 1150.

COMING SOON!

```
/*******************************************************************************
Finding permutation by its length and number in lexicographical order
Works in O(n^2)
Based on problem 190 from informatics.mccme.ru
http://informatics.mccme.ru/moodle/mod/statements/view.php?chapterid=190#1
*******************************************************************************/
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
using namespace std;
const int MAXN = 20;
int n, num;
bool used[MAXN];
int f[MAXN];
void permutationByNumber(int n, int num) {
for (int i = 1; i <= n; i++)
used[i] = false;
int cur = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (used[j])
continue;
int add = f[n - i];
if (cur + add >= num) {
used[j] = true;
printf("%d ", j);
break;
}
cur += add;
}
}
printf("\n");
}
int main() {
//assert(freopen("input.txt","r",stdin));
//assert(freopen("output.txt","w",stdout));
scanf("%d", &n);
scanf("%d", &num);
f[0] = 1;
for (int i = 1; i <= n; i++) {
f[i] = f[i - 1] * i;
}
permutationByNumber(n, num);
return 0;
}
```