📜  求系列 3, 11, 31, 69, 的第 n 项。 . . . .

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

求系列 3, 11, 31, 69, 的第 n 项。 . . . .

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

例子:

方法:

从给定的系列中,找到第 N 项的公式 -

给定系列的第 N 项可以概括为-

插图:

以下是上述方法的实现 -

C++
// C++ program to find nth
// term of the series
#include 
using namespace std;
 
// Function to return nth
// term of the series
int find_nth_Term(int n)
{
    return n * n * n + (n + 1);
}
 
// Driver code
int main()
{
    // Find given nth term
    int n = 5;
 
    // Function call
    cout << find_nth_Term(n) << endl;
    return 0;
}


Java
// Java code for the above approach
import java.io.*;
 
class GFG {
 
  // Function to return nth
  // term of the series
  static int find_nth_Term(int n)
  {
    return n * n * n + (n + 1);
  }
 
  // Driver code
  public static void main(String[] args)
  {
 
    // Find given nth term
    int n = 5;
 
    // Function call
    System.out.println(find_nth_Term(n));
  }
}
 
// This code is contributed by Potta Lokesh


Python
# Python program to find nth
# term of the series
 
# Function to return nth
# term of the series
def find_nth_Term(n):
     
    return n * n * n + (n + 1)
 
# Driver code
 
# Find given nth term
n = 5
 
# Function call
print(find_nth_Term(n))
 
# This code is contributed by Samim Hossain Mondal.


C#
// C# program to find nth
// term of the series
using System;
class GFG
{
 
  // Function to return nth
  // term of the series
  static int find_nth_Term(int n)
  {
    return n * n * n + (n + 1);
  }
 
  // Driver code
  public static int Main()
  {
 
    // Find given nth term
    int n = 5;
 
    // Function call
    Console.WriteLine(find_nth_Term(n));
    return 0;
  }
}
 
// This code is contributed by Taranpreet


Javascript


输出
131

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