Find Nth term of the series 3, 14, 39, 84…

Given a number N. The task is to write a program to find the Nth term in the below series:

3, 14, 39, 84…

Examples:



Input: 3
Output: 39
For N = 3
Nth term = ( 3*3*3 ) + ( 3*3 ) + 3
         = 39

Input: 4
Output: 84

Formula to calculate the Nth term of the series:

Nth term = ( N*N*N ) + ( N*N ) + N 

Below is the required implementation:

C++

filter_none

edit
close

play_arrow

link
brightness_4
code

// CPP program to find N-th term of the series:
// 3, 14, 38, 84...
#include <iostream>
using namespace std;
  
// calculate Nth term of series
int nthTerm(int N)
{
    return (N * N * N) + (N * N) + N;
}
  
// Driver Function
int main()
{
    int N = 3;
  
    cout << nthTerm(N);
  
    return 0;
}

chevron_right


Java

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to find Nth number
import java.io.*;
  
// calculate Nth term of this series
class GFG 
{
public int nthTerm(int N)
{
    // By using above formula
    return (N * N * N) + (N * N) + N;
}
  
// Driver Code
public static void main(String[] args)
{
    int N = 3;
    GFG a = new GFG();
  
    // call and print Nth term
    System.out.println(a.nthTerm(N));
}
}

chevron_right


Python 3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python 3 program to find  N-th 
# term of the series: 
# 3, 14, 38, 84... 
  
# Function to calculate Nth term of series  
def nthTerm(n) :
  
    return (N * N * N) + (N * N) + N
  
# Driver code
if __name__ == "__main__" :
  
     N = 3
  
     # function calling
     print(nthTerm(N))
  
# This code is contributed by ANKITRAI1

chevron_right


C#

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to find Nth number
using System;
  
// calculate Nth term of this series
class GFG 
{
public int nthTerm(int N)
{
    // By using above formula
    return (N * N * N) + (N * N) + N;
}
  
// Driver Code
public static void Main()
{
    int N = 3;
    GFG a = new GFG();
  
    // call and print Nth term
    Console.WriteLine(a.nthTerm(N));
}
}
  
// This code is contributed
// by inder_verma.

chevron_right


PHP

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP program to find N-th term  
// of the series: 3, 14, 38, 84... 
  
// calculate Nth term of series 
function nthTerm($N
    return ($N * $N * $N) + 
           ($N * $N) + $N
  
// Driver Code 
$N = 3; 
  
echo nthTerm($N); 
  
// This code is contributed 
// by Shivi_Aggarwal
?>

chevron_right


Output:

39

GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.