Find Nth term of the series 1, 8, 54, 384…
Given a number N. The task is to write a program to find the Nth term in the below series:
1, 8, 54, 384...
Examples:
Input : 3
Output : 54
For N = 3
Nth term = ( 3*3) * 3!
= 54
Input : 2
Output : 8
On observing carefully, the Nth term in the above series can be generalized as:
Nth term = ( N*N ) * ( N! )
Below is the implementation of the above approach:
C++
// CPP program to find N-th term of the series: // 1, 8, 54, 384... #include <iostream> using namespace std; // calculate factorial of N int fact(int N) { int i, product = 1; for (i = 1; i <= N; i++) product = product * i; return product; } // calculate Nth term of series int nthTerm(int N) { return (N * N) * fact(N); } // Driver Function int main() { int N = 4; cout << nthTerm(N); return 0; } |
chevron_right
filter_none
Java
// Java program to find N-th term of the series: // 1, 8, 54, 384... import java.io.*; // Main class for main method class GFG { public static int fact(int N) { int i, product = 1; // Calculate factorial of N for (i = 1; i <= N; i++) product = product * i; return product; } public static int nthTerm(int N) { // By using above formula return (N * N) * fact(N); } public static void main(String[] args) { int N = 4; // 4th term is 384 System.out.println(nthTerm(N)); } } |
chevron_right
filter_none
Python 3
# Python 3 program to find # N-th term of the series: # 1, 8, 54, 384... # calculate factorial of N def fact(N): product = 1 for i in range(1, N + 1): product = product * i return product # calculate Nth term of series def nthTerm(N): return (N * N) * fact(N) # Driver Code if __name__ =="__main__": N = 4 print(nthTerm(N)) # This code is contributed # by ChitraNayal |
chevron_right
filter_none
C#
// C# program to find N-th // term of the series: // 1, 8, 54, 384... using System; class GFG { public static int fact(int N) { int i, product = 1; // Calculate factorial of N for (i = 1; i <= N; i++) product = product * i; return product; } public static int nthTerm(int N) { // By using above formula return (N * N) * fact(N); } // Driver Code public static void Main(String[] args) { int N = 4; // 4th term is 384 Console.WriteLine(nthTerm(N)); } } // This code is contributed // by Kirti_Mangal |
chevron_right
filter_none
PHP
<?php // PHP program to find N-th /// term of the series: // 1, 8, 54, 384... // calculate factorial of N function fact($N) { $product = 1; for ($i = 1; $i <= $N; $i++) $product = $product * $i; return $product; } // calculate Nth term of series function nthTerm($N) { return ($N * $N) * fact($N); } // Driver Code $N = 4; echo nthTerm($N); // This code is contributed // by ChitraNayal ?> |
chevron_right
filter_none
Output:
384
Time Complexity: O(N)
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 1, 1, 2, 6, 24...
- Find Nth term of the series 0, 6, 0, 12, 0, 90...
- 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 3, 9, 21, 41, 71...
- Find Nth term of the series 0, 2, 4, 8, 12, 18...
- Find the nth term of the series 0, 8, 64, 216, 512, . . .
- Find Nth term of the series 5, 13, 25, 41, 61...
- Find Nth term of the series 3, 14, 39, 84...
- Find the nth term of the given series
- Find n-th term of series 2, 10, 30, 68, 130 ...
- Find the Nth term of the series 14, 28, 20, 40,.....
- Find n-th term in the series 9, 33, 73,129 ...
- Find n-th term of series 1, 4, 27, 16, 125, 36, 343 .......
- Find sum of Series with n-th term as n^2 - (n-1)^2
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.



