# Find Nth term of the series 1, 5, 32, 288 …

Given a number n, the task is to find the n-th term in series 1, 5, 32, 288 …

**Examples:**

Input: N = 3 Output: 32 Explanation: 3rd term = 3^3 + 2^2 + 1^1 = 32 Input: N = 4 Output: 288 Explanation: 4th term = 4^4 + 3^3 + 2^2 + 1^1 = 288

**Approach:**

Nth term = n^n + (n-1)^(n-1) + (n-2)^(n-2) + ……..1^1.

Implementation of the above approach is given below:

## C++

`// CPP code to generate 'Nth' terms ` `// of this sequence ` ` ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to generate a fixed \number ` `int` `nthTerm(` `int` `N) ` `{ ` ` ` `int` `nth = 0, i; ` ` ` ` ` `// Finding nth term ` ` ` `for` `(i = N; i > 0; i--) { ` ` ` ` ` `nth += ` `pow` `(i, i); ` ` ` `} ` ` ` `return` `nth; ` `} ` ` ` `// Driver Method ` `int` `main() ` `{ ` ` ` `int` `N = 3; ` ` ` `cout << nthTerm(N) << endl; ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java code to generate 'Nth' terms ` `// of this sequence ` `import` `java.lang.Math; ` `class` `GFG { ` ` ` ` ` `// Function to generate a fixed \number ` ` ` `public` `static` `int` `nthTerm(` `int` `N) ` ` ` `{ ` ` ` `int` `nth = ` `0` `, i; ` ` ` ` ` `// Finding nth term ` ` ` `for` `(i = N; i > ` `0` `; i--) { ` ` ` ` ` `nth += Math.pow(i, i); ` ` ` `} ` ` ` `return` `nth; ` ` ` `} ` ` ` ` ` `// Driver Method ` ` ` `public` `static` `void` `main(String[] args) ` ` ` `{ ` ` ` `int` `N = ` `3` `; ` ` ` `System.out.println(nthTerm(N)); ` ` ` `} ` `} ` `// This code is contributed by 29AjayKumar ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 code to generate 'Nth' ` `# terms of this sequence ` ` ` `# Function to generate a ` `# fixed number ` `def` `nthTerm(N): ` ` ` `nth ` `=` `0` ` ` ` ` `# Finding nth term ` ` ` `for` `i ` `in` `range` `(N, ` `0` `, ` `-` `1` `): ` ` ` `nth ` `+` `=` `pow` `(i, i) ` ` ` `return` `nth ` ` ` `# Driver code ` `N ` `=` `3` `print` `(nthTerm(N)) ` ` ` `# This code is contributed ` `# by Shrikant13 ` |

*chevron_right*

*filter_none*

## C#

`// C# code to generate 'Nth' terms ` `// of this sequence ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` ` ` `// Function to generate a fixed \number ` ` ` `public` `static` `int` `nthTerm(` `int` `N) ` ` ` `{ ` ` ` `int` `nth = 0, i; ` ` ` ` ` `// Finding nth term ` ` ` `for` `(i = N; i > 0; i--) ` ` ` `{ ` ` ` `nth +=(` `int` `)Math.Pow(i, i); ` ` ` `} ` ` ` `return` `nth; ` ` ` `} ` ` ` ` ` `// Driver Method ` ` ` `public` `static` `void` `Main() ` ` ` `{ ` ` ` `int` `N = 3; ` ` ` `Console.WriteLine(nthTerm(N)); ` ` ` `} ` `} ` ` ` `// This code is contributed by Code_Mech. ` |

*chevron_right*

*filter_none*

## PHP

0; $i–)

{

$nth += pow($i, $i);

}

return $nth;

}

// Driver Code

$N = 3;

echo(nthTerm($N));

// This code is contributed by Code_Mech.

?>

**Output:**

32

**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 5 2 13 41
- Find n-th term in the series 7, 15, 32, ...
- Find Nth term of the series 0, 6, 0, 12, 0, 90...
- Find n-th term of series 1, 3, 6, 10, 15, 21...
- Find n-th term in the series 9, 33, 73,129 ...
- Find Nth term of the series 3, 14, 39, 84...
- Find the Nth term of the series 1 + 2 + 6 + 15 + 31 + 56 + ...
- Find Nth term of the series 1, 1, 2, 6, 24...
- Find n-th term in series 1 2 2 3 3 3 4 4 4 4....
- Find n-th term of series 2, 10, 30, 68, 130 ...
- Find Nth term of the series 1, 8, 54, 384...
- Find the nth term of the series 0, 8, 64, 216, 512, . . .
- Find the nth term of the given series
- Find n-th term of series 3, 9, 21, 41, 71...

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.