# Second Pentagonal numbers

The second pentagonal numbers are a collection of objects which can be arranged in the form of a regular pentagon.

Second Pentagonal series is:

2, 7, 15, 26, 40, 57, 77, 100, 126, …..

### Find the Nth term of the Second Pentagonal Series

Given an integer N. The task is to find the N-th term of the second pentagonal series.

Examples:

Input: N = 1
Output: 2

Input: N = 4
Output: 26

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

Approach: The idea is to find the general term of the series which can be computed with the help of the following observations as below:

Series = 2, 7, 15, 26, 40, 57, 77, 100, 126, …..

Difference = 7 – 2, 15 – 7, 26 – 15, 40 – 26, …………….
= 5, 8, 11, 14……which is an AP

So nth term of given series
nth term = 2 + (5 + 8 + 11 + 14 …… (n-1)terms)
= 2 + (n-1)/2*(2*5+(n-1-1)*3)
= 2 + (n-1)/2*(10+3n-6)
= 2 + (n-1)*(3n+4)/2
= n*(3*n + 1)/2

Therefore, the Nth term of the series is given as Below is the implementation of above approach:

## C++

 // C++ implementation to  // find N-th term in the series     #include  #include  using namespace std;     // Function to find N-th term  // in the series  void findNthTerm(int n)  {      cout << n * (3 * n + 1) / 2           << endl;  }     // Driver code  int main()  {      int N = 4;      findNthTerm(N);         return 0;  }

## Java

 // Java implementation to  // find N-th term in the series  class GFG{     // Function to find N-th term  // in the series  static void findNthTerm(int n)  {      System.out.print(n * (3 *                        n + 1) / 2 + "\n");  }     // Driver code  public static void main(String[] args)  {      int N = 4;      findNthTerm(N);  }  }     // This code is contributed by 29AjayKumar

## Python3

 # Python3 implementation to  # find N-th term in the series     # Function to find N-th term  # in the series  def findNthTerm(n):         print(n * (3 * n + 1) // 2, end = " ");     # Driver code  N = 4;  findNthTerm(N);     # This code is contributed by Code_Mech

## C#

 // C# implementation to  // find N-th term in the series  using System;  class GFG{     // Function to find N-th term  // in the series  static void findNthTerm(int n)  {      Console.Write(n * (3 *                     n + 1) / 2 + "\n");  }     // Driver code  public static void Main()  {      int N = 4;      findNthTerm(N);  }  }     // This code is contributed by Code_Mech

Output:

26


Reference: https://oeis.org/A005449

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.

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.

Improved By : 29AjayKumar, Code_Mech

Article Tags :
Practice Tags :

1

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.