Find Nth term of the series 1, 6, 18, 40, 75, ….
Given a number n, the task is to find the n-th term in series 1, 6, 18, 40, 75, …
Example:
Input: N = 2
Output: 6
Explanation:
2nd term = (2^2*(2+1))/2
= 6
Input: N = 5
Output: 75
Explanation:
5th term = (5^2*(5+1))/2
= 75
Approach:
Nth term = (N^2*(N+1))/2
Implementation of the above approach is given below:
C++
// CPP code to generate // 'Nth' term of this sequence #include <bits/stdc++.h> using namespace std; // Function to generate a fixed number int nthTerm(int N) { int nth = 0; //(N^2*(N+1))/2 nth = (N * N * (N + 1)) / 2; return nth; } // Driver Method int main() { int N = 5; cout << nthTerm(N) << endl; return 0; } |
chevron_right
filter_none
Java
// Java code to generate // 'Nth' term of this sequence class GFG { // Function to generate a fixed number public static int nthTerm(int N) { int nth = 0; //(N^2*(N+1))/2 nth = (N * N * (N + 1)) / 2; return nth; } // Driver Method public static void main(String[] args) { int N = 5; System.out.println(nthTerm(N)); } // This code is contributed by 29AjayKumar } |
chevron_right
filter_none
Python3
# python program to find out'Nth' term of this sequence # Function to generate a fixed number def nthTerm(N): nth = 0 nth = (N * N * (N + 1))//2 return nth # Driver code N = 5print(nthTerm(N)) # This code is contributed by Shrikant13 |
chevron_right
filter_none
C#
// C# code to generate // 'Nth' term of this sequence using System; public class GFG { // Function to generate a fixed number public static int nthTerm(int N) { int nth = 0; //(N^2*(N+1))/2 nth = (N * N * (N + 1)) / 2; return nth; } // Driver Method public static void Main(string[] args) { int N = 5; Console.WriteLine(nthTerm(N)); } } // This code is contributed by Shrikant13 |
chevron_right
filter_none
PHP
<?php // PHP code to generate // 'Nth' term of this sequence // Function to generate a fixed number function nthTerm($N) { $nth = 0; // (N^2*(N+1))/2 $nth = ($N * $N * ($N + 1)) / 2; return $nth; } // Driver Code $N = 5; echo nthTerm($N); // This code is contributed // by chandan_jnu ?> |
chevron_right
filter_none
Output:
75
Time Complexity: O(1)
Recommended Posts:
- Find the Nth term of the series where each term f[i] = f[i - 1] - f[i - 2]
- Find the Nth term of the series 2 + 6 + 13 + 23 + . . .
- Find Nth term of the series 3, 14, 39, 84...
- Find n-th term of series 1, 3, 6, 10, 15, 21...
- Find n-th term of series 3, 9, 21, 41, 71...
- Find the Nth term of the series 14, 28, 20, 40,.....
- Find the Nth term of the series 1 + 2 + 6 + 15 + 31 + 56 + ...
- Find Nth term of the series 1, 8, 54, 384...
- Find n-th term in series 1 2 2 3 3 3 4 4 4 4....
- Find sum of Series with n-th term as n^2 - (n-1)^2
- Find n-th term in the series 7, 15, 32, ...
- Find Nth term of the series 1, 1, 2, 6, 24...
- Find n-th term in the series 9, 33, 73,129 ...
- Find the nth term of the series 0, 8, 64, 216, 512, . . .
- Find nth Term of the Series 1 2 2 4 4 4 4 8 8 8 8 8 8 8 8 ...
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.



