# Find N-th term in the series 0, 4, 18, 48, 100 …

**Given** a series **0, 4, 18, 48, 100 . . .** and an integer **N**, the task is to find the **N-th term** of the series.

**Examples:**

Input:N = 4Output:48Explanation:As given in the sequence we can see that 4th term is 48

Input:N = 6Output:180

**Approach: **Consider the below observation:

For N = 2, the 2nd term is 4, which can be represented as 8 – 4, i.e. 2

^{3}– 2^{2}For N = 3, the 3rd term is 18, which can be represented as 27 – 9, i.e. 3

^{3}– 3^{2}For N = 4, the 4th term is 18, which can be represented as 27 – 9, i.e. 4

^{3}– 4^{2}.

.

.

Similarly, The

N-th term of this series can be represented as N^{3}– N^{2}

So for any N, find the **square** of that N and **subtract** it from the **cube** of the number.

Below is the implementation of the above approach:

## C++

`// C++ code to find Nth term of series` `// 0, 4, 18, ...` ` ` `#include <bits/stdc++.h>` `using` `namespace` `std;` ` ` `// Function to find N-th term` `// of the series` `int` `getNthTerm(` `int` `N)` `{` ` ` `// (pow(N, 3) - pow(N, 2))` ` ` `return` `(N * N * N) - (N * N);` `}` ` ` `// Driver Code` `int` `main()` `{` ` ` `int` `N = 4;` ` ` ` ` `// Get the 8th term of the series` ` ` `cout << getNthTerm(N);` ` ` `return` `0;` `}` |

## Java

`// Java code to find Nth term of series` `// 0, 4, 18, ...` `class` `GFG` `{` ` ` ` ` `// Function to find N-th term` ` ` `// of the series` ` ` `public` `static` `int` `getNthTerm(` `int` `N) ` ` ` `{` ` ` ` ` `// (pow(N, 3) - pow(N, 2))` ` ` `return` `(N * N * N) - (N * N);` ` ` `}` ` ` ` ` `// Driver Code` ` ` `public` `static` `void` `main(String args[])` ` ` `{` ` ` `int` `N = ` `4` `;` ` ` ` ` `// Get the 8th term of the series` ` ` `System.out.println(getNthTerm(N));` ` ` `}` `}` ` ` `// This code is contributed by gfgking` |

## Python3

`# Python code to find Nth term of series` `# 0, 4, 18, ...` ` ` `# Function to find N-th term` `# of the series` `def` `getNthTerm(N):` ` ` ` ` `# (pow(N, 3) - pow(N, 2))` ` ` `return` `(N ` `*` `N ` `*` `N) ` `-` `(N ` `*` `N);` ` ` `# Driver Code` `N ` `=` `4` `;` ` ` `# Get the 8th term of the series` `print` `(getNthTerm(N));` ` ` `# This code is contributed by gfgking` |

## C#

`// C# code to find Nth term of series` `// 0, 4, 18, ...` ` ` `using` `System;` `class` `GFG {` ` ` `// Function to find N-th term` ` ` `// of the series` ` ` `public` `static` `int` `getNthTerm(` `int` `N) {` ` ` `// (pow(N, 3) - pow(N, 2))` ` ` `return` `(N * N * N) - (N * N);` ` ` `}` ` ` ` ` `// Driver Code` ` ` `public` `static` `void` `Main() {` ` ` `int` `N = 4;` ` ` ` ` `// Get the 8th term of the series` ` ` `Console.Write(getNthTerm(N));` ` ` `}` `}` ` ` `// This code is contributed by gfgking` |

## Javascript

`<script>` `// Javascript code to find Nth term of series` `// 0, 4, 18, ...` ` ` ` ` ` ` `// Function to find N-th term` `// of the series` `function` `getNthTerm(N) {` ` ` `// (pow(N, 3) - pow(N, 2))` ` ` `return` `(N * N * N) - (N * N);` `}` ` ` `// Driver Code` ` ` `let N = 4;` ` ` `// Get the 8th term of the series` `document.write(getNthTerm(N));` `// This code is contributed by gfgking` `</script>` |

**Output**

48

**Time complexity: **O(1)**Auxiliary space: **O(1)

Attention reader! Don’t stop learning now. Get hold of all the important mathematical concepts for competitive programming with the **Essential Maths for CP Course** at a student-friendly price. To complete your preparation from learning a language to DS Algo and many more, please refer **Complete Interview Preparation Course****.**