I want to get the 48th element of the Fibonacci sequence which I can store in a 64 bit integer. I am using a recursive subroutine, but it is taking forever to finish. If anyone can find a problem with my recursive subroutine, I would be very grateful.
Integer (Int8) :: n
Integer (Int64) :: fib64
n = Int (48, Int8)
Call fibonacci_genr (fib64, n)
Here is my recursive subroutine
Recursive &
Subroutine fibonacci_genr &
( &
fb, n &
)
Integer (Int64), Intent (Out) :: fb
Integer (Int8), Intent (In) :: n
Integer (Int64) :: fb1, fb2
If (n < 2) Then
fb = Int (n, Int64)
Else
Call fibonacci_genr (fb1, n-1)
Call fibonacci_genr (fb2, n-2)
fb = fb1 + fb2
End If
End Subroutine fibonacci_genr