Fibonacci por Cálculo Linear

      
      { Fibonacci por calculo direto }
      { Joao Paulo Schwarz Schuler }
      { http://www.schulers.com/jpss }
      
      {$X+}
      function Fib(N:longint):longint;
      { Fibonacci por calculo direto }
      var I:longint;
          Serie:array[0..2] of longint;
      begin
      Serie[0]:=0;
      Serie[1]:=1;
      if N<=1
         then Fib:=N
         else begin
              for I:= 2 to N
                  do Serie[I mod 3]:=Serie[(I-1) mod 3]+Serie[(I-2) mod 3];
              Fib:=Serie[N mod 3];
              end;
      end;
      
      var I:integer;
      begin
      for I:=0 to 46 do
          writeln(I:6,':',Fib(I):20);
      end.