Find the Nth term of the series 1, 2, 6, 21, 88, 445. . .

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 = 3Output: 6
Input: N = 6Output: 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++
Java
Python3
C#
Javascript
// C++ program to find N-th term// of the series-// 1, 2, 6, 21, 88, 445...#include <bits/stdc++.h>using namespace std; // Function to return Nth term// of the seriesint nthTerm(int N){    // Initializing a variable    int term = 1;     // Loop to iterate from 1 to N-1    for (int i = 1; i < N; i++)    {        // Multiplying and adding previous        // element with i        term = term * i + i;    }     // returning the Nth term    return term;} // Driver Codeint main(){    // Get the value of N    int N = 6;    cout << nthTerm(N);    return 0;}
// Java program to find N-th term// of the series-// 1, 2, 6, 21, 88, 445...class GFG{       // Function to return Nth term    // of the series    static int nthTerm(int N)    {               // Initializing a variable        int term = 1;         // Loop to iterate from 1 to N-1        for (int i = 1; i < N; i++)        {                       // Multiplying and adding previous            // element with i            term = term * i + i;        }         // returning the Nth term        return term;    }     // Driver Code    public static void main(String args[])    {               // Get the value of N        int N = 6;        System.out.println(nthTerm(N));    } } // This code is contributed by saurabh_jaiswal.
# Python code for the above approach # Function to return Nth term# of the seriesdef nthTerm(N):     # Initializing a variable    term = 1;     # Loop to iterate from 1 to N-1    for i in range(1, N):               # Multiplying and adding previous        # element with i        term = term * i + i;     # returning the Nth term    return term; # Driver Code # Get the value of NN = 6;print(nthTerm(N)); # This code is contributed by Saurabh Jaiswal
// C# program to find N-th term// of the series-// 1, 2, 6, 21, 88, 445...using System;class GFG{   // Function to return Nth term  // of the series  static int nthTerm(int N)  {     // Initializing a variable    int term = 1;     // Loop to iterate from 1 to N-1    for (int i = 1; i < N; i++)    {       // Multiplying and adding previous      // element with i      term = term * i + i;    }     // returning the Nth term    return term;  }   // Driver Code  public static void Main()  {     // Get the value of N    int N = 6;    Console.Write(nthTerm(N));  } } // This code is contributed by Samim Hossain Mondal.
<script>        // JavaScript code for the above approach         // Function to return Nth term        // of the series        function nthTerm(N)        {                     // Initializing a variable            let term = 1;             // Loop to iterate from 1 to N-1            for (let i = 1; i < N; i++)            {                             // Multiplying and adding previous                // element with i                term = term * i + i;            }             // returning the Nth term            return term;        }         // Driver Code         // Get the value of N        let N = 6;        document.write(nthTerm(N));   // This code is contributed by Potta Lokesh    </script>
445
Time Complexity: O(N)
Auxiliary Space: O(1)
lokeshpotta20
_saurabh_jaiswal
samim2000
series
Mathematical
Pattern Searching
Mathematical
series
Pattern Searching
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Algorithm to solve Rubik's Cube
Merge two sorted arrays with O(1) extra space
Program to print prime numbers from 1 to N.
Find next greater number with same set of digits
Segment Tree | Set 1 (Sum of given range)
KMP Algorithm for Pattern Searching
Rabin-Karp Algorithm for Pattern Searching
Check if a string is substring of another
Check if an URL is valid or not using Regular Expression
Boyer Moore Algorithm for Pattern Searching