📜  求系列 3、5、9、17、33 的第 N 项。 .

📅  最后修改于: 2022-05-13 01:56:08.143000             🧑  作者: Mango

求系列 3、5、9、17、33 的第 N 项。 .

给定一个正整数N ,任务是找到序列的第 N项-

例子:

方法:

考虑下面的例子:

因此,我们可以使用上述观察来找出序列的第 N项的关系:

以下是上述方法的实现 -

C++
// C++ program to implement
// the above approach
#include 
using namespace std;
 
// Function to return Nth
// term of the series
int findTerm(int N)
{
    return pow(2, N) + 1;
}
 
// Driver Code
int main()
{
    int N = 6;
    cout << findTerm(N);
    return 0;
}


Java
// Java program to implement
// the above approach
import java.io.*;
 
class GFG {
 
  // Function to return Nth
  // term of the series
  static int findTerm(int N)
  {
    return (int)Math.pow(2, N) + 1;
  }
 
  // Driver Code
  public static void main (String[] args)
  {
    int N = 6;
    System.out.print(findTerm(N));
  }
}
 
// This code is contributed by Shubham Singh


Python3
# Python program to implement
# the above approach
 
# Function to return Nth
# term of the series
def findTerm(N):
    return (2 ** N) + 1;
 
# Driver Code
N = 6;
print(findTerm(N));
 
# This code is contributed by gfgking


C#
// C# program to implement
// the above approach
using System;
class GFG
{
 
  // Function to return Nth
  // term of the series
  static int findTerm(int N)
  {
    return (int)Math.Pow(2, N) + 1;
  }
 
  // Driver Code
  public static void Main()
  {
    int N = 6;
    Console.Write(findTerm(N));
  }
}
 
// This code is contributed by Samim Hossain Mondal.


Javascript


输出
65

时间复杂度: O(1)
辅助空间: O(1)