VOOZH about

URL: https://www.geeksforgeeks.org/dsa/find-nth-fibonacci-number-using-golden-ratio/

⇱ Find nth Fibonacci number Using Golden ratio - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Find nth Fibonacci number Using Golden ratio

Last Updated : 8 May, 2026

Given a non-negative integer n, your task is to find the nthFibonaccinumber. The Fibonacci sequence is a sequence where the next term is the sum of the previous two terms. The first two terms of the Fibonacci sequence are 0 followed by 1. The Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21

The Fibonacci sequence is defined as follows:

  • F(0) = 0
  • F(1) = 1
  • F(n) = F(n - 1) + F(n - 2) for n > 1

Examples: 

Input: n = 5
Output: 5
Explanation: The 5th Fibonacci number is 5.

Input: n = 0
Output: 0 
Explanation: The 0th Fibonacci number is 0. 

Using Golden Ratio

The Fibonacci sequence can be approximated using the golden ratio: where, .Since, the ratio of consecutive Fibonacci numbers approaches φ, we can use this property to compute the next number.

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). Hence, this method is reliable only from the 5th term onward. After:






Note:

  • This method can calculate first 34 fibonacci numbers correctly. After that there may be difference from the correct value due to floating point arithmetic errors.
  • We can optimize above solution work in O(Log n) by using Efficient Method to Compute Power.

Output
Fibonacci Number: 5

Time complexity: O(n)
Auxiliary space: O(1)

Comment
Article Tags: