1. Убрать рекурсию (сделать через вычисление с памятью и цикл)
2. Использовать Int64 (на всякий случай)
Как-то так (не проверял, мог чего-то напутать слегка):
Код:
unit Fibonachi;
interface
function Fib(N : Integer) : Int64;
implementation
var
int_Fibs : Array Of Int64;
function Fib(N : Integer) : Int64;
begin
If N < 1 Then Result := -1 Else
If N <= Length(int_Fibs) Then Result := int_Fibs[N-1] Else
Begin
For I := Length(int_Fibs) To N Do
Begin
SetLength(int_Fibs,Length(int_Fibs)+1);
int_Fibs[i] := int_Fibs[I-1] + int_Fibs[I-2];
End;
Result := int_Fibs[High(int_Fibs)];
End;
end;
initialization
SetLength(int_Fibs,2);
int_Fibs[0] := 1;
int_Fibs[1] := 1;
finalization
SetLength(int_Fibs,0);
end.