Fibonacci Expression
Submissions: 385   Accuracy:

35.58%

  Difficulty: Easy   Marks: 2

Given a number N, the task is to evaluate the below expression. Expected time complexity is O(1).

                                                           f(n-1)*f(n+1) - f(n)*f(n)

Where f(n) is the n-th Fibonacci number with n >= 1. First few Fibonacci numbers are 0, 1, 1, 2, 3, 5, 8, 13, ………..i.e. (considering 0 as 0th Fibonacci number)

Input:
The first line of input contains an integer T denoting the number of test cases. Each test case contains an integer n for which the expression needs to be evaluated.

Output:
Print an integer which is the required value.

Constraints:
1<=T<=10000
1<=n<=100000

Example:
Input:

2
5
6

Output:
-1
1

Explanation:

For n=5,
f(5-1=4) = 3
f(5+1=6) = 8
f(5)*f(5)= 5*5 = 25
f(4)*f(6)- f(5)*f(5)= 24-25= -1

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Shashwat Jain
Author: shashwat jain


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.