#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <string>
using namespace std;
const int MAXN = 12;
long long f[MAXN];
int ans[MAXN];
bool vis[MAXN];
void init()
{
f[0] = 1;
for (int i = 1; i < MAXN; i++)
{
f[i] = f[i - 1] * i;
}
}
void input()
{
int n, m;
while (cin >> n >> m)
{
m--;
memset(vis, false, sizeof(vis));
for (int i = 0; i < n; i++)
{
int t = m / f[n - i - 1], cnt = 0, k = 0;
m %= f[n - i - 1];
for (int j = 1; j <= n; j++)
{
k = j;
if (cnt == t) break;
if (!vis[j]) cnt++;
}
while (vis[k]) k++;
vis[k] = true;
ans[i] = k;
}
for (int i = 0; i < n; i++)
{
cout << ans[i];
}
cout << endl;
}
}
int main()
{
init();
input();
return 0;
}
康拓逆运算
最新推荐文章于 2024-09-06 23:25:44 发布