TREENUM - Tree Num
Tác giả: RR
Ngôn ngữ: Pascal
{$R-,Q-}
{$Mode objFPC}
uses math;
const
FINP = '';
FOUT = '';
MAXN = 64;
scs = 40;
type
big = array[0..scs] of longint;
procedure add(var a,b,c:big); inline;
var
i,nho:longint;
begin
nho:=0;
c[0]:=max(a[0],b[0]);
for i:=1 to c[0] do
begin
c[i]:=a[i]+b[i]+nho;
if c[i]<10 then nho:=0 else begin c[i]-=10; nho:=1; end;
end;
if nho=1 then
begin
inc(c[0]);
c[c[0]]:=1;
end;
end;
var
f1,f2 : text;
test : longint;
n : qword;
lt3 : array[0..64] of big;
res : big;
procedure openF;
begin
assign(f1,FINP); reset(f1);
assign(f2,FOUT); rewrite(f2);
end;
procedure closeF;
begin
close(f1);
close(f2);
end;
procedure init;
var
i:longint;
begin
lt3[0][0]:=1; lt3[0][1]:=1;
for i:=1 to 64 do
begin
add(lt3[i-1],lt3[i-1],lt3[i]);
add(lt3[i-1],lt3[i] ,lt3[i]);
end;
end;
procedure solve;
var
i:longint;
begin
fillchar(res,sizeof(res),0);
for i:=0 to 64 do
if (n>>i) and 1=1 then
add(res,lt3[i],res);
if res[0]=0 then begin writeln(f2,0); exit; end;
for i:=res[0] downto 1 do
write(f2,res[i]);
writeln(f2);
end;
begin
openF;
init;
read(f1,test);
for test:=1 to test do
begin
read(f1,n);
solve;
end;
closeF;
end.