Given a number N. The task is to write a program to find the Nth term in the below series:
0, 2, 4, 8, 12, 18…
Input: 3 Output: 4 For N = 3 Nth term = ( 3 + ( 3 - 1 ) * 3 ) / 2 = 4 Input: 5 Output: 12
On observing carefully, the Nth term in the above series can be generalized as:
Nth term = ( N + ( N - 1 ) * N ) / 2
Below is the implementation of the above approach:
Time Complexity: O(1)
- Find Nth term of the series 1, 8, 54, 384...
- Find Nth term of series 1, 4, 15, 72, 420...
- Program to find Nth term of series 9, 23, 45, 75, 113...
- Program to find the Nth term of series -1, 2, 11, 26, 47......
- std::find in C++
- unordered_map find in C++ STL
- set find() function in C++ STL
- string find in C++
- multimap find() in C++ STL
- map find() function in C++ STL
- How to find the sum of elements of an Array using STL in C++?
- multiset find() function in C++ STL
- How to find the sum of elements of a Vector using STL in C++?
- Find elements of an Array which are Odd and Even using STL in C++
- unordered_multimap find() function in C++ STL
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.