Given an integer . The task is to write a program to find the **N-th** term of the given series:

1 + 2 + 6 + 15 + 31 + 56 + ...

**Examples**:

Input : N = 8 Output : 141 Input : N = 20 Output : 2471

**Approach:**

The given series is:

1, 2, 6, 15, 31, 56, 92, 141, ...

**First consecutive difference**:

1 4 9 16 25 36 49 .......

**Second consecutive difference**:

3 5 7 9 11 13......

As the second consecutive difference is in AP, the nth term (t_{n}) of the series is of the form,

A(n – 1)(n – 2)(n – 3) + B(n – 1)(n – 2) + C(n – 1) + D

So, t_{n} = A(n – 1)(n – 2)(n – 3) + B(n – 1)(n – 2) + C(n – 1) + D

Now,

t_{1} = D = 1

t_{2} = C (2 – 1) + D = 2

t_{3} = 2B + 2C + D = 6

t_{4} = CA + 6B + 3C + D = 15

On solving the above four equations we get => A = 1/3, B = 3/2, C = 1, D = 1. On substituting these values t_{n} and after simplifying we get,

Below is the implementation of above approach:

## C++

`// C++ program to find Nth ` `// term of the series: ` `// 1 + 2 + 6 + 15 + 31 + 56 + ... ` `#include<iostream> ` `#include<math.h> ` `using` `namespace` `std; ` ` ` `// calculate Nth term of given series ` `int` `Nth_Term(` `int` `n) ` `{ ` ` ` `return` `(2 * ` `pow` `(n, 3) - 3 * ` ` ` `pow` `(n, 2) + n + 6) / 6; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `N = 8; ` ` ` `cout << Nth_Term(N); ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to find Nth ` `// term of the series: ` `// 1 + 2 + 6 + 15 + 31 + 56 + ... ` `import` `java.util.*; ` `import` `java.lang.*; ` ` ` `class` `GFG ` `{ ` `// calculate Nth term of given series ` `static` `double` `Nth_Term(` `int` `n) ` `{ ` ` ` `return` `(` `2` `* Math.pow(n, ` `3` `) - ` `3` `* ` ` ` `Math.pow(n, ` `2` `) + n + ` `6` `) / ` `6` `; ` `} ` ` ` `// Driver code ` `static` `public` `void` `main (String args[]) ` `{ ` ` ` `int` `N = ` `8` `; ` ` ` `System.out.println(Nth_Term(N)); ` `} ` `} ` ` ` `// This code is contributed ` `// by Akanksha Rai ` |

*chevron_right*

*filter_none*

## Python3

`# Python program to find Nth term of the series: ` `# 1 + 2 + 6 + 15 + 31 + 56 + ... ` ` ` `# calculate Nth term of given series ` `def` `Nth_Term(n): ` ` ` `return` `(` `2` `*` `pow` `(n, ` `3` `) ` `-` `3` `*` `pow` `(n, ` `2` `) ` `+` `n ` `+` `6` `) ` `/` `/` `6` ` ` `# Driver code ` `N ` `=` `8` `print` `(Nth_Term(N)) ` |

*chevron_right*

*filter_none*

## C#

`// C# program to find Nth ` `// term of the series: ` `// 1 + 2 + 6 + 15 + 31 + 56 + ... ` `using` `System; ` ` ` `class` `GFG ` `{ ` `// calculate Nth term of given series ` `static` `double` `Nth_Term(` `int` `n) ` `{ ` ` ` `return` `(2 * Math.Pow(n, 3) - 3 * ` ` ` `Math.Pow(n, 2) + n + 6) / 6; ` `} ` ` ` `// Driver code ` `static` `public` `void` `Main () ` `{ ` ` ` `int` `N = 8; ` ` ` `Console.WriteLine(Nth_Term(N)); ` `} ` `} ` ` ` `// This code is contributed ` `// by Sach_Code ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP program to find Nth ` `// term of the series: ` `// 1 + 2 + 6 + 15 + 31 + 56 + .. ` ` ` `// calculate Nth term of given series ` `function` `Nth_Term(` `$n` `) ` `{ ` ` ` `return` `(2 * pow(` `$n` `, 3) - 3 * ` ` ` `pow(` `$n` `, 2) + ` `$n` `+ 6) / 6; ` `} ` ` ` `// Driver code ` `$N` `= 8; ` ` ` `echo` `Nth_Term(` `$N` `); ` ` ` `// This code is contributed by ` `// Shashank_Sharma ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

141

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Nth term where K+1th term is product of Kth term with difference of max and min digit of Kth term
- Find the Nth term of the series where each term f[i] = f[i - 1] - f[i - 2]
- Find Nth term of the series where each term differs by 6 and 2 alternately
- Nth term of a sequence formed by sum of current term with product of its largest and smallest digit
- Program to find Nth term in the given Series
- Program to find the Nth term of the series 3, 7, 13, 21, 31.....
- Program to find Nth term of series 1, 3, 12, 60, 360…
- Program to find the Nth term of series -1, 2, 11, 26, 47......
- Program to find Nth term in the series 0, 0, 2, 1, 4, 2, 6, 3, 8,...
- Program to find Nth term of series 9, 23, 45, 75, 113...
- Program to find Nth term in the series 0, 2, 1, 3, 1, 5, 2, 7, 3,…
- Find Nth term of the series 5, 13, 25, 41, 61...
- Program to find the Nth term of the series 3, 20, 63, 144, 230, ……
- Program to find the Nth term of series 5, 10, 17, 26, 37, 50, 65, 82, ...
- Program to find the Nth term of series 0, 4, 14, 30, 51, 80, 114, 154, 200, ...
- Find Nth term of the series 3, 14, 39, 84...
- Program to find the Nth term of the series 0, 14, 40, 78, 124, ...
- Program to find the Nth term of the series 0, 5, 14, 27, 44, ........
- Find Nth term of the series 1, 8, 54, 384...
- Find Nth term of the series 1, 1, 2, 6, 24...

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.