by boy_behind_glasses » Thu Nov 18, 2004 3:01 pm
[pascal]type bigint=array[1..1500] of byte;
var skt:array[0..5000] of word;
a:array[0..5000] of bigint;
max,i,j,n:word;
procedure cong(x,y,z:word);
var i:integer;
nho:byte;
so:byte;
max:byte;
begin
fillchar(a[z],sizeof(a[z]),0);
nho:=0;
max:=((skt[x]+skt[y])+abs(skt[x]-skt[y])) div 2;
for i:=1 to max do
begin
so:=a[x][i]+a[y][i]+nho;
nho:=so div 10;
so:=so mod 10;
a[z][i]:=so;
end;
skt[z]:=max;
if nho>0 then
begin
inc(skt[z]);
a[z,skt[z]]:=nho;
end;
end;
begin
fillchar(a,sizeof(a),0);
fillchar(skt,sizeof(skt),0);
skt[0]:=1; skt[1]:=1;
a[0][1]:=1; a[1][1]:=1;
max:=1;
n:=1;
while n<>0 do
begin
read(n);
if n=0 then break;
if skt[n]=0 then
for i:=max to n do
if skt[i]=0 then cong(i-1,i-2,i);
if n>max then max:=n;
write('The Fibonacci number for ',n,' is ');
for j:=skt[n] downto 1 do write(a[n,j]);
writeln;
end;
end.[/pascal]