Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Find nth term of series 3, 11, 31, 69, . . . . .

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Given an integer N, the task is to find the Nth term of the series 

3, 11, 31, 69, . . . . . till Nth term.

Examples:

Input: N = 3 
Output: 31

Input: N = 6
Output: 223

 

Approach:

From the given series, find the formula for Nth term

1st term = 1 ^ 3 + (1 + 1) = 3

2nd term = 2 ^ 3 + (2 + 1) = 11

3rd term = 3 ^ 3 + (3 + 1) = 31

4th term = 4 ^ 3 + (4 + 1) = 69

.

.

Nth term = n  ^ 3 + (n + 1)

The Nth term of the given series can be generalized as-

TN = n  ^ 3 + (n + 1)

Illustration:

Input: N = 5
Output: 131
Explanation:
TN = n  ^ 3 + (n + 1)   
     = 5 ^ 3 + (5 + 1)    
     = 131

Below is the implementation of the above approach-

C++




// C++ program to find nth
// term of the series
#include <iostream>
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




<script>
// Javascript program to find nth
// term of the series
 
// Function to return nth
// term of the series
function find_nth_Term(n)
{
    return n * n * n + (n + 1);
}
 
// Driver code
// Find given nth term
let n = 5;
 
// Function call
document.write(find_nth_Term(n))
 
// This code is contributed by gfgking.
</script>

Output

131

Time Complexity: O(1), since there is no loop or recursion.
Auxiliary Space: O(1), since no extra space has been taken.


My Personal Notes arrow_drop_up
Last Updated : 20 Aug, 2022
Like Article
Save Article
Similar Reads
Related Tutorials