Given an integer N and a sequence (1), (3, 5), (7, 9, 11), (13, 15, 17, 19), ….. the task is to find the sum of all the numbers in Nth parenthesis.
Input: N = 2
3 + 5 = 8
Input: N = 3
7 + 9 + 11 = 27
Approach: It can be observed that for the values of N = 1, 2, 3, … a series will be formed as 1, 8, 27, 64, 125, 216, 343, … whose Nth term is N3
Below is the implementation of the above approach:
Time Complexity: O(1)
- How to swap two numbers without using a temporary variable?
- Lucky Numbers
- Ugly Numbers
- Write a program to add two numbers in base 14
- Count of Binary Digit numbers smaller than N
- Program for Fibonacci numbers
- Average of a stream of numbers
- Add two numbers without using arithmetic operators
- To find sum of two numbers without using any operator
- Count numbers that don't contain 3
- Count numbers with same first and last digits
- Russian Peasant (Multiply two numbers using bitwise operators)
- Write a function that generates one of 3 numbers according to given probabilities
- Print squares of first n natural numbers without using *, / and -
- Print all increasing sequences of length k from 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.