Given an integer N, the task is to find the N-th Fibonacci numbers.
Input: N = 3
F(1) = 1, F(2) = 1
F(3) = F(1) + F(2) = 2
Input: N = 6
- The Matrix Exponentiation Method is already discussed before. The Doubling Method can be seen as an improvement to the matrix exponentiation method to find the N-th Fibonacci number although it doesn’t use matrix multiplication itself.
The Fibonacci recursive sequence is given by
F(n+1) = F(n) + F(n-1)
The Matrix Exponentiation method uses the following formula
The method involves costly matrix multiplication and moreover Fn is redundantly computed twice.
On the other hand, Fast Doubling Method is based on two basic formulas:
F(2n) = F(n)[2F(n+1) – F(n)] F(2n + 1) = F(n)2 + F(n+1)2
Here is a short explanation of the above results:
F(n+1) = F(n) + F(n-1) &
F(n) = F(n)
It can be rewritten in the matrix form as:
For doubling, we just plug in “2n” into the formula:
Substituting F(n-1) = F(n+1)- F(n) and after simplification we get,
Below is the implementation of the above approach:
Time Complexity: Repeated squaring reduces time from linear to logarithmic . Hence, with constant time arithmetic, the time complexity is O(log n).
- Check if a M-th fibonacci number divides N-th fibonacci number
- Program to find last two digits of Nth Fibonacci number
- Find nth Fibonacci number using Golden ratio
- Program to find Nth odd Fibonacci Number
- Check if sum of Fibonacci elements in an Array is a Fibonacci number or not
- Find the Nth element of the modified Fibonacci series
- G-Fact 18 | Finding nth Fibonacci Number using Golden Ratio
- Nth Even Fibonacci Number
- C/C++ Program for nth multiple of a number in Fibonacci Series
- Nth XOR Fibonacci number
- Nth Fibonacci number using Pell's equation
- Sum of nth terms of Modified Fibonacci series made by every pair of two arrays
- Nth Term of a Fibonacci Series of Primes formed by concatenating pairs of Primes in a given range
- Karatsuba algorithm for fast multiplication using Divide and Conquer algorithm
- Fast I/O for Competitive Programming
- Fast I/O in Java in Competitive Programming
- Fast Fourier Transformation for poynomial multiplication
- Iterative Fast Fourier Transformation for polynomial multiplication
- Find Nth number in a sequence which is not a multiple of a given number
- Find Index of given fibonacci number in constant time
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.