Given a positive integer N, the task is to find Fib(N)2 – (Fib(N-1) * Fib(N+1)) where Fib(N) returns the Nth Fibonacci number.
Input: N = 3
Fib(3) * Fib(3) – Fib(2) * Fib(4) = 4 – 3 = 1
Input: N = 2
Fib(2) * Fib(2) – Fib(1) * Fib(3) = 1 – 2 = -1
Approach: This question can be approached by first trying out a few test cases. Let’s take a few examples:
For N = 1 : Fib(1) * Fib(1) – Fib(0) * Fib(2) = 1 – 0 = 1
For N = 2 : Fib(2) * Fib(2) – Fib(1) * Fib(3) = 1 – 2 = -1
For N = 3 : Fib(3) * Fib(3) – Fib(2) * Fib(4) = 4 – 3 = 1
For N = 4 : Fib(4) * Fib(4) – Fib(3) * Fib(5) = 9 – 10 = -1
We observe here that when N is even then the answer will be -1 and when the N is odd then the answer will be 1.
Below is the implementation of the above approach:
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Check if sum of Fibonacci elements in an Array is a Fibonacci number or not
- Secretary Problem (A Optimal Stopping Problem)
- Check if a M-th fibonacci number divides N-th fibonacci number
- Transportation Problem | Set 7 ( Degeneracy in Transportation Problem )
- Even Fibonacci Numbers Sum
- Nth Even Fibonacci Number
- Fibonacci modulo p
- Fibonacci Power
- Fibonacci Word
- K- Fibonacci series
- Fibonacci Coding
- Fibonacci Search
- Sum of Fibonacci Numbers
- GCD and Fibonacci Numbers
- Non Fibonacci Numbers
- Nth XOR Fibonacci number
- Find the next fibonacci number
- Tail Recursion for Fibonacci
- Fibonacci Heap | Set 1 (Introduction)
- Fibonacci number in an array
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.