Fibonacci series = 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ……..
Different methods to find nth Fibonacci number are already discussed. Another simple way of finding nth Fibonacci number is using golden ratio as Fibonacci numbers maintain approximate golden ratio till infinite.
Input : n = 9 Output : 34 Input : n = 7 Output : 13
Golden ratio may give us incorrect answer.
We can get correct result if we round up the result at each point.
nth fibonacci number = round(n-1th Fibonacci number X golden ratio) fn = round(fn-1 *
Till 4th term, the ratio is not much close to golden ratio (as 3/2 = 1.5, 2/1 = 2, …). So, we will consider from 5th term to get next fibonacci number. To find out the 9th fibonacci number f9 (n = 9) :
f6 = round(f5 *
) = 8 f7 = round(f6 * ) = 13 f8 = round(f7 * ) = 21 f9 = round(f8 * ) = 34
Note: This method can calculate first 34 fibonacci numbers correctly. After that there may be difference from the correct value.
Below is the implementation of above approach:
9th Fibonacci Number = 34
We can optimize above solution work in O(Log n) by using efficient method to compute power.
The above method may not always produce correct results as floating point computations are involved. This is the reason, this method is not used practically even if it can be optimized to work in O(Log n). Please refer below MIT video for more details.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- G-Fact 18 | Finding nth Fibonacci Number using Golden Ratio
- Deriving the expression of Fibonacci Numbers in terms of golden ratio
- Check whether two numbers are in golden ratio
- Ratio of mth and nth terms of an A. P. with given ratio of sums
- Find the number which when added to the given ratio a : b, the ratio changes to c : d
- Sum of two numbers if the original ratio and new ratio obtained by adding a given number to each number is given
- Check if a M-th fibonacci number divides N-th fibonacci number
- Ratio of mth and nth term in an Arithmetic Progression (AP)
- Program to find last two digits of Nth Fibonacci number
- Program to find Nth odd Fibonacci Number
- Fast Doubling method to find the Nth Fibonacci number
- Nth Fibonacci number using Pell's equation
- Check if sum of Fibonacci elements in an Array is a Fibonacci number or not
- Find the Nth element of the modified Fibonacci series
- Nth Even Fibonacci Number
- Nth XOR Fibonacci number
- C/C++ Program for nth multiple of a number in Fibonacci Series
- Sum of nth terms of Modified Fibonacci series made by every pair of two arrays
- Nth term of a Custom Fibonacci series
- Nth Term of a Fibonacci Series of Primes formed by concatenating pairs of Primes in a given range
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.
Improved By : jit_t