Given a series of natural numbers divided into groups as: (1, 2), (3, 4, 5, 6), (7, 8, 9, 10, 11, 12), (13, 14, 15, 16, 17, 18, 19, 20)….. and so on. Given a number N, the task is to find the sum of the numbers in the N^{th} group.

**Examples:**

Input: N = 3Output: 57 Numbers in 3rd group are: 7, 8, 9, 10, 11, 12Input: N = 10Output: 2010

The first group has **2** terms,

second group has **4** terms,

.

.

.

nth group has **2n** terms.

Now,

The last term of the **first group** is 2 = 1 × (1 + 1)

The last term of the **second group** is 6 = 2 × (2 + 1)

The last term of the **third group** is 12 = 3 × (3 + 1)

The last term of the **fourth group** is 20 = 4 × (4 + 1)

.

.

.

The last term of the **nth group = n(n + 1)**.

Therefore, the sum of the numbers in the **nth group** is:

= sum of all the numbers upto

nth group– sum of all the numbers upto(n – 1)th group= [1 + 2 +……..+ n(n + 1)] – [1 + 2 +……..+ (n – 1 )((n – 1) + 1)]

=

=

=

=

Below is the implementation of above approach:

## C++

`// C++ program to find sum in Nth group ` `#include<bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `//calculate sum of Nth group ` `int` `nth_group(` `int` `n){ ` ` ` `return` `n * (2 * ` `pow` `(n, 2) + 1); ` `} ` ` ` `//Driver code ` `int` `main() ` `{ ` ` ` ` ` `int` `N = 5; ` ` ` `cout<<nth_group(N); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to find sum ` `// in Nth group ` `import` `java.util.*; ` ` ` `class` `GFG ` `{ ` ` ` `// calculate sum of Nth group ` `static` `int` `nth_group(` `int` `n) ` `{ ` ` ` `return` `n * (` `2` `* (` `int` `)Math.pow(n, ` `2` `) + ` `1` `); ` `} ` ` ` `// Driver code ` `public` `static` `void` `main(String arr[]) ` `{ ` ` ` `int` `N = ` `5` `; ` ` ` `System.out.println(nth_group(N)); ` `} ` `} ` ` ` `// This code is contributed by Surendra ` |

*chevron_right*

*filter_none*

## Python3

`# Python program to find sum in Nth group ` ` ` `# calculate sum of Nth group ` `def` `nth_group(n): ` ` ` `return` `n ` `*` `(` `2` `*` `pow` `(n, ` `2` `) ` `+` `1` `) ` ` ` `# Driver code ` `N ` `=` `5` `print` `(nth_group(N)) ` |

*chevron_right*

*filter_none*

## C#

`// C# program to find sum in Nth group ` ` ` `using` `System; ` ` ` `class` `gfg ` `{ ` ` ` `//calculate sum of Nth group ` ` ` `public` `static` `double` `nth_group(` `int` `n) ` ` ` `{ ` ` ` `return` `n * (2 * Math.Pow(n, 2) + 1); ` ` ` `} ` ` ` ` ` `//Driver code ` ` ` `public` `static` `int` `Main() ` ` ` `{ ` ` ` `int` `N = 5; ` ` ` `Console.WriteLine(nth_group(N)); ` ` ` `return` `0; ` ` ` `} ` `} ` `// This code is contributed by Soumik ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP program to find sum ` `// in Nth group ` ` ` `// calculate sum of Nth group ` `function` `nth_group(` `$n` `) ` `{ ` ` ` `return` `$n` `* (2 * pow(` `$n` `, 2) + 1); ` `} ` ` ` `// Driver code ` `$N` `= 5; ` `echo` `nth_group(` `$N` `); ` ` ` `// This code is contributed ` `// by jit_t ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

255

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:

- Find the Nth natural number which is not divisible by A
- Nicomachus’s Theorem (Sum of k-th group of odd positive numbers)
- Difference between sum of the squares of first n natural numbers and square of sum
- Sum of sum of all subsets of a set formed by first N natural numbers
- Difference between Sum of Cubes and Sum of First N Natural Numbers
- Sum of sum-series of first N Natural numbers
- Sum of series formed by difference between product and sum of N natural numbers
- Check if a given number can be expressed as pair-sum of sum of first X natural numbers
- Find ways an Integer can be expressed as sum of n-th power of unique natural numbers
- Program to find sum of first n natural numbers
- Find maximum N such that the sum of square of first N natural numbers is not more than X
- Find the permutation of first N natural numbers such that sum of i % P
_{i}is maximum possible - Find if given number is sum of first n natural numbers
- Minimize the sum of the squares of the sum of elements of each group the array is divided into
- Find the sum of the first Nth Icosagonal Numbers
- Find the sum of the first Nth Centered Tridecagonal Numbers
- Fill the missing numbers in the array of N natural numbers such that arr[i] not equal to i
- Group all co-prime numbers from 1 to N
- Sum of all proper divisors of natural numbers in an array
- Sum of cubes of first n odd natural numbers

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.