📜  求系列 4、11、30、85、248 的第 N 项。 .

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

求系列 4、11、30、85、248 的第 N 项。 .

给定一个正整数N 。任务是找到系列的第 N项:

例子:

方法:

给定序列的第 N 项可以概括为:

插图:

下面是上述问题的实现:

C++
// C++ program to find N-th term
// of the series-
// 4, 11, 30, 85, 248...
#include 
using namespace std;
 
// Function to return Nth term
// of the series
int nthTerm(int N)
{
    return pow(3, N) + N;
}
 
// Driver Code
int main()
{
    // Get the value of N
    int N = 4;
    cout << nthTerm(N);
    return 0;
}


Java
// Java program to find N-th term
// of the series-
// 4, 11, 30, 85, 248...
class GFG
{
 
  // Function to return Nth term
  // of the series
  static int nthTerm(int N) {
    return (int)Math.pow(3, N) + N;
  }
 
  // Driver Code
  public static void main(String args[])
  {
 
    // Get the value of N
    int N = 4;
    System.out.println(nthTerm(N));
  }
}
 
// This code is contributed by saurabh_jaiswal.


Python3
# Python code for the above approach
 
# Function to return Nth term
# of the series
def nthTerm(N):
    return (3 ** N) + N;
 
# Driver Code
# Get the value of N
N = 4;
print(nthTerm(N));
 
# This code is contributed by Saurabh Jaiswal


C#
// C# program to find N-th term
// of the series-
// 4, 11, 30, 85, 248...
using System;
class GFG
{
 
  // Function to return Nth term
  // of the series
  static int nthTerm(int N) {
    return (int)Math.Pow(3, N) + N;
  }
 
  // Driver Code
  public static void Main()
  {
 
    // Get the value of N
    int N = 4;
    Console.Write(nthTerm(N));
  }
}
 
// This code is contributed by Samim Hossain Mondal.


Javascript



输出
85

时间复杂度: O(1)

辅助空间: O(1)