Find the Nth term of the series 1, 2, 6, 21, 88, 445. . .
Last Updated :
14 Jan, 2022
Given a positive integer N. The task is to find Nth term of the series:
1, 2, 6, 21, 88, 445, . . .
Examples:
Input: N = 3
Output: 6
Input: N = 6
Output: 445
Approach:
The given sequence follows the following pattern-
1, (1 * 1 + 1 = 2), (2 * 2 + 2 = 6), (6 * 3 + 3 = 21), (21 * 4 + 4 = 88), (88 * 5 + 5 = 445), …
Below steps can be used to solve the problem-
- For each iterative i, multiplying its previous element with i (Initially the element will be 1)
- And add multiplied elements with i.
- Finally, return the Nth term of the series.
Below is the implementation of the above approach
C++
#include <bits/stdc++.h>
using namespace std;
int nthTerm( int N)
{
int term = 1;
for ( int i = 1; i < N; i++)
{
term = term * i + i;
}
return term;
}
int main()
{
int N = 6;
cout << nthTerm(N);
return 0;
}
|
Java
class GFG
{
static int nthTerm( int N)
{
int term = 1 ;
for ( int i = 1 ; i < N; i++)
{
term = term * i + i;
}
return term;
}
public static void main(String args[])
{
int N = 6 ;
System.out.println(nthTerm(N));
}
}
|
Python3
def nthTerm(N):
term = 1 ;
for i in range ( 1 , N):
term = term * i + i;
return term;
N = 6 ;
print (nthTerm(N));
|
C#
using System;
class GFG
{
static int nthTerm( int N)
{
int term = 1;
for ( int i = 1; i < N; i++)
{
term = term * i + i;
}
return term;
}
public static void Main()
{
int N = 6;
Console.Write(nthTerm(N));
}
}
|
Javascript
<script>
function nthTerm(N)
{
let term = 1;
for (let i = 1; i < N; i++)
{
term = term * i + i;
}
return term;
}
let N = 6;
document.write(nthTerm(N));
</script>
|
Time Complexity: O(N)
Auxiliary Space: O(1)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...