📜  斐波那契问题(Fib(N)* Fib(N)– Fib(N-1)* Fib(N + 1)的值)

📅  最后修改于: 2021-04-23 05:42:23             🧑  作者: Mango

给定正整数N ,任务是找到Fib(N) 2 –(Fib(N-1)* Fib(N + 1)) ,其中Fib(N)返回第N个斐波那契数。

例子:

方法:首先尝试一些测试用例就可以解决这个问题。让我们举几个例子:

下面是上述方法的实现:

C++
// C++ implementation of the approach
#include 
using namespace std;
  
int getResult(int n)
{
    if (n & 1)
        return 1;
    return -1;
}
  
// Driver code
int main()
{
    int n = 3;
    cout << getResult(n);
}


Java
//Java implementation of the approach
  
import java.io.*;
  
class GFG {
      
static int getResult(int n)
{
    if ((n & 1)>0)
        return 1;
    return -1;
}
  
// Driver code
    public static void main (String[] args) {
      
    int n = 3;
    System.out.println(getResult(n));
    }
//This code is contributed by @Tushil.    
}


Python3
# Python 3 implementation of 
# the approach
def getResult(n):
  
    if n & 1:
        return 1
    return -1
  
# Driver code
n = 3
print(getResult(n))
  
# This code is contributed 
# by Shrikant13


C#
//C# implementation of the approach
  
using System;
  
class GFG {
      
static int getResult(int n)
{
    if ((n & 1)>0)
        return 1;
    return -1;
}
  
// Driver code
    public static void Main () {
      
    int n = 3;
    Console.WriteLine(getResult(n));
    }
//This code is contributed by anuj_67..
}


PHP


输出:
1