NKGIFTS - VOI08 Quà tết
Tác giả: flashmt
Ngôn ngữ: Pascal
const fi='';
fo='';
base=1000000000;
dg=9;
type bignum=array[0..100] of longint;
var n:longint;
x,y:qword;
z,h:bignum;
p:array[0..41] of qword;
procedure rf;
begin
read(n,x,y);
y:=p[n]-1-y;
end;
procedure wf;
var i,j,t:longint; s:string;
begin
for i:=z[0] downto 1 do
begin
if i<z[0] then
begin
str(z[i],s);
t:=length(s);
for j:=t+1 to dg do write(0);
end;
write(z[i]);
end;
write(' ');
end;
procedure plus(var h:bignum);
var i,mem:longint;
begin
mem:=0;
for i:=1 to h[0] do
begin
h[i]:=h[i] shl 1+mem;
if h[i]>=base then
begin
mem:=1;
h[i]:=h[i]-base;
end
else mem:=0;
end;
if mem>0 then
begin
inc(h[0]);
h[h[0]]:=1;
end;
end;
procedure minus(var a:bignum;b,c:bignum);
var i,mem:longint;
begin
mem:=-1;
for i:=1 to b[0] do
begin
a[i]:=b[i]-c[i]-mem;
if a[i]<0 then
begin
a[i]:=a[i]+base;
mem:=1;
end
else mem:=0;
end;
a[0]:=b[0];
while (a[a[0]]=0) and (a[0]>1) do dec(a[0]);
end;
procedure pr;
var i:longint;
begin
fillchar(z,sizeof(z),0);
fillchar(h,sizeof(h),0);
z[0]:=1; z[1]:=1; h[0]:=1; h[1]:=1;
for i:=n downto 1 do
begin
plus(h);
if x>=p[i-1] then
begin
minus(z,h,z);
x:=p[i]-1-x;
end;
plus(h);
if y>=p[i-1] then
begin
minus(z,h,z);
y:=p[i]-1-y;
end;
end;
minus(z,h,z);
wf;
end;
procedure init;
var i:longint;
begin
p[0]:=1;
for i:=1 to 41 do p[i]:=p[i-1]*2;
end;
begin
assign(input,fi); reset(input);
assign(output,fo); rewrite(output);
init;
rf;
pr;
read(x,y);
y:=p[n]-1-y;
pr;
close(input); close(output);
end.