Find the nth term of the given series
Given the first two terms of the series as 1 and 6 and all the elements of the series are 2 less than the mean of the number preceding and succeeding it. The task is to print the nth term of the series.
First few terms of the series are:
1, 6, 15, 28, 45, 66, 91, …
Examples:
Input: N = 3
Output: 15Input: N = 1
Output: 1
Approach: The given series represents odd positioned numbers in the triangular number series. Since the nth triangular number can easily be found by (n * (n + 1) / 2), so for finding the odd numbers we can replace n by (2 * n) – 1 as (2 * n) – 1 will always result in odd numbers i.e. the nth number of the given series will be ((2 * n) – 1) * n.
Below is the implementation of the above approach:
C++
// C++ implementation of the approach #include <bits/stdc++.h> using namespace std; // Function to return the nth term // of the given series int oddTriangularNumber(int N) { return (N * ((2 * N) - 1)); } // Driver code int main() { int N = 3; cout << oddTriangularNumber(N); return 0; } |
Java
// Java implementation of the approach class GFG { // Function to return the nth term // of the given series static int oddTriangularNumber(int N) { return (N * ((2 * N) - 1)); } // Driver code public static void main(String[] args) { int N = 3; System.out.println(oddTriangularNumber(N)); } } // This code contributed by Rajput-Ji |
Python3
# Python 3 implementation of the approach # Function to return the nth term # of the given series def oddTriangularNumber(N): return (N * ((2 * N) - 1)) # Driver code if __name__ == '__main__': N = 3 print(oddTriangularNumber(N)) # This code is contributed by # Surendra_Gangwar |
C#
// C# implementation of the approach using System; class GFG { // Function to return the nth term // of the given series static int oddTriangularNumber(int N) { return (N * ((2 * N) - 1)); } // Driver code public static void Main(String[] args) { int N = 3; Console.WriteLine(oddTriangularNumber(N)); } } /* This code contributed by PrinciRaj1992 */ |
PHP
<?php // PHP implementation of the approach // Function to return the nth term // of the given series function oddTriangularNumber($N) { return ($N * ((2 * $N) - 1)); } // Driver code $N = 3; echo oddTriangularNumber($N); // This code is contributed by Ryuga ?> |
15
Recommended Posts:
- Find the Nth term of the series where each term f[i] = f[i - 1] - f[i - 2]
- Find Nth term of the series 0, 6, 0, 12, 0, 90...
- Find n-th term in the series 7, 15, 32, ...
- Find Nth term of the series 3, 14, 39, 84...
- Find n-th term of series 2, 10, 30, 68, 130 ...
- Find Nth term of the series 5, 13, 25, 41, 61...
- Find the Nth term of the series 1 + 2 + 6 + 15 + 31 + 56 + ...
- Find sum of Series with n-th term as n^2 - (n-1)^2
- Find the nth term of the series 0, 8, 64, 216, 512, . . .
- Find n-th term of series 3, 9, 21, 41, 71...
- Find the Nth term of the series 2 + 6 + 13 + 23 + . . .
- Find nth Term of the Series 1 2 2 4 4 4 4 8 8 8 8 8 8 8 8 ...
- Find n-th term of series 1, 3, 6, 10, 15, 21...
- Find n-th term in series 1 2 2 3 3 3 4 4 4 4....
- Find Nth term of the series 1, 5, 32, 288 ...
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.



