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 Nth group.
Input : N = 3 Output : 57 Numbers in 3rd group are: 7, 8, 9, 10, 11, 12 Input : N = 10 Output : 2010
The first group has 2 terms,
second group has 4 terms,
nth group has 2n terms.
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:
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.
- Find m-th summation of first n natural numbers.
- Find if given number is sum of first n natural numbers
- Find all divisors of first N natural numbers
- Program to find sum of first n natural numbers
- Find the average of first N natural numbers
- Find the good permutation of first N natural numbers
- Find the K-th Permutation Sequence of first N natural numbers
- Find the permutation of first N natural numbers such that sum of i % Pi is maximum possible
- Find maximum N such that the sum of square of first N natural numbers is not more than X
- Find permutation of first N natural numbers that satisfies the given condition
- Find the count of natural Hexadecimal numbers of size N
- Find the number of sub arrays in the permutation of first N natural numbers such that their median is M
- Find ways an Integer can be expressed as sum of n-th power of unique natural 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
- Nicomachus’s Theorem (Sum of k-th group of odd positive numbers)
- Natural Numbers
- Sum of first n natural numbers
- LCM of First n Natural Numbers
- Sum of fifth powers of the first n 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 firstname.lastname@example.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.