题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2062
详细分析:http://mamicode.com/info-detail-95273.html
http://www.xuebuyuan.com/445957.html
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#define LL long long
#define mod 1000000007
#define inf 1<<30
#define N 2010
using namespace std;
LL a[],b[];
void init()
{
a[]=;
for(int i=;i<=;i++)a[i]=(a[i-]+)*i;
}
int main()
{
LL n,m;
init();
while(scanf("%I64d%I64d",&n,&m)>)
{
for(int i=;i<=n;i++)b[i]=i;
while(m!=)
{
int t=m/(a[n]/n)+(m%(a[n]/n)?:);
printf("%d",b[t]);
m-=(a[n]/n)*(t-)+;
if(m)printf(" ");
for(int i=t;i<n;i++)b[i]=b[i+];
n--;
}
puts("");
}
}