Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionprocedure Fibonacci(n: integer) : integer; begin Case n of 0..1 : return n; else return ( Fibonacci(n-1) + Fibonacci(n-2) ); end; end;
function FibonacciF(const N: byte): Extended; var I : integer; A,B: Extended; begin A := 0; B := 1; result := N; for I := 2 to N do begin result := A + B; A := B; B := result; end; end; function Fibonacci(const N: byte {0..92}): UInt64; var I : integer; A,B: UInt64; begin A := 0; B := 1; result := N; for I := 2 to N do begin result := A + B; A := B; B := result; end; end;
type Int64Couple = array[0..1] of Int64; function Fibonacci(n: integer): Int64; function FibonacciSteps(n: integer): Int64Couple; var fk : Int64Couple; fk0, fk1, fk0sq, fk1sq : Int64; begin case n of 0 : begin result[0] := 1; result[1] := 0; end; else begin fk := FibonacciSteps(n div 2); fk0 := fk[0]; fk1 := fk[1]; fk0sq := fk0*fk0; fk1sq := fk1*fk1; case n mod 2 of 0 : begin result[0] := fk1sq + fk0sq; result[1] := fk1*fk0*2 + fk1sq; end; 1 : begin result[0] := fk1*fk0*2 + fk1sq; result[1] := (fk1+fk0)*(fk1+fk0) + fk1sq; end; end; end; end; end; begin result := ((FibonacciSteps(n))[0]); end;