P
poseidon225


Đề : giả bài toán Tháp Hà Nội ta có h(1)=1,h(n)=2h(n-1).giả sử mỗi lần chuyễn là 1 giây. Hỏi để chuyễn 64 lần cần bao nhiêu lâu ( tính ra độ chính xác ngày )
Mình viết thử trong FPC, chạy dc phần tính H(64) còn phần kia hem hỉu sao lại báo lỗi.
Các Pro giúp tớ với
Mình viết thử trong FPC, chạy dc phần tính H(64) còn phần kia hem hỉu sao lại báo lỗi.
Các Pro giúp tớ với
Program thaphanoi;
Uses Crt;
Type Bigint=array[1..1000]of integer;
Var a,thuong:int64;
du,d,d2,rong:bigint;
Function nhan2(n1:bigint):bigint;
Var i,t:integer;
Begin
t:=0;
For i:=1 to 1000 do
begin
t:=2*n1+t;
nhan2:=t mod 10;
t:=t div 10;
end;
end;
Function hieu(m2,n2:bigint):bigint;
Var i,c:integer;
Begin
c:=0;
For i:=1 to 1000 do
begin
c:=m2-n2-c;
If c<0 then begin
hieu:=c+10;
c:=1;
end
else begin
hieu:=c;
c:=0;
end;
end;
end;
Function ss(m,n:bigint):string;
Var i:integer;
Begin
For i:=1000 downto 1 do
If m>n then exit('lon')
else if m<n then exit('nho')
else exit('bang');
end;
Procedure chia(m3,n3:bigint);
Var tg,i:integer;
Begin
if ss(hieu(m3,n3),n3)='nho' then
begin
For i:=1 to 1000 do
du:=hieu(m3,n3);
exit;
end
else begin
inc(;
end;
Function H(n:integer):bigint;
Begin
If n=1 then h[1]:=1
else h:=nhan2(h(n-1));
end;
Procedure xuly;
var s:string;
j:int64;
i:integer;
Begin
j:=3600*24*365;
str(j,s);
For i:=1 to length(s) do
d:=ord(s)-48;
j:=3600*24;
str(j,s);
For i:=1 to length(s) do
d2:=ord(s)-48;
end;
Begin
Clrscr;
thuong:=0;
{fillchar(rong,sizeof(rong),0);
fillchar(du,sizeof(du),0);
fillchar(du,sizeof(d),0);
fillchar(du,sizeof(d2),0);}
xuly;
Chia(h(6thuong);
chia(hieu(m3,n3),n3);
end4),d);
Write(' _ Can ',thuong,' nam ');
If ss(du,rong)<>'bang' then begin
chia(du,d2);
write(thuong,' ngay ');
end;
readln;
end.