Podemos usar el tipo TSuperlargo del que ya te hable en el otro hilo.
Código Delphi
[-]
type
TSuperLargo = array[0..30] of Byte;
function AddSuper(var a,b: TSuperLargo; Acarreo: Integer): TSuperLargo; overload;
var
i,j: integer;
begin
for i := 0 to 30 do
begin
j:= (Integer(a[i]) + Integer(b[i])) + Acarreo;
Result[i]:= j mod 10;
Acarreo:= j div 10;
end;
end;
function AddSuper(a,b: TSuperLargo): TSuperLargo; overload;
begin
Result:= AddSuper(a,b,0);
end;
function SuperToStr(a: TSuperLargo): string;
var
i: integer;
flag: Boolean;
begin
Result:= '';
flag:= FALSE;
for i := 30 downto 0 do
begin
if flag then
Result:= Result + IntToStr(a[i])
else if a[i] > 0 then
begin
flag:= TRUE;
Result:= Result + IntToStr(a[i]);
end;
end;
end;
function fibonacci(n: integer): string;
var
i,j,k: TSuperLargo;
Str: string;
begin
FillChar(i,Sizeof(i),0);
FillChar(j,Sizeof(j),0);
FillChar(k,Sizeof(k),0);
i[0]:= 1;
j[0]:= 1;
Result:= '';
while Result = '' do
begin
k:= j;
j:= AddSuper(i,j);
i:= k;
Str:= SuperToStr(j);
if Length(Str)>n then
Result:= SuperToStr(i);
end;
end;
ShowMessage(fibonacci(20));
La respuesta es:
x = 83621143489848422977