- 全排列
- 2013-09-25 21:16:53 @
const b:array[1..20]of int64=(
1,2,6,24,120,720,5040,40320,362880,3628800,
39916800,479001600,6227020800,87178291200,
1307674368000,20922789888000,355687428096000,
6402373705728000,121645100408832000,2432902008176640000);
var i,z:longint;p,t,q,m,n:int64; a:array[1..20]of string;
s:string;
procedure make(x,y:longint);
var j:longint;
begin
for j:= x to y do
a[j]:=a[j+1];
end;
begin
readln(m,n);
s:='';
for i:= 1 to m do str(i,a[i]);
t:=b[m]; p:=b[m-1];
for i:= m downto 1 do
begin
q:=((n-1) div p) +1;
s:=s+a[q]+' ';
make(q,i);
t:=b[i-1];
n:=n mod p;
p:=b[i-2];
if (n=0)or(n=1) then break;
end;
if n=0 then begin
for z:= i-1 downto 1 do s:=s+a[z]+' ';
end else if n=1 then
for z:= 1 to i-1 do s:=s+a[z]+' ';
writeln(s);
end.