Given a number N. The task is to write a program to find the N-th term in the below series:

1, 1, 2, 3, 4, 9, 8, 27, 16, 81, 32, 243, 64, 729, 128, 2187…

**Examples**:

Input : 4 Output : 3 Input : 11 Output : 32

On observing carefully, you will find that the series is a mixture of 2 series:

- All the odd terms in this series form a geometric series.
- All the even terms form yet another geometric series.

The approach to solving the problem is quite simple. The odd positioned terms in the given series form a GP series with first term = 1 and common ration = 2. Similarly, the even positioned terms in the given series form a GP series with first term = 1 and common ration = 3.

Therefore first check whether the input number N is even or odd. If it is even, set N=N/2(since there are Two GP series running parallely) and find the Nth term by using formula **a _{n} = a_{1}·r^{n-1}** with r=3.

Similarly, if N is odd, set N=(n/2)+1 and do the same as previous with r=2.

Below is the implementation of above approach:

## C++

`// C++ program to find Nth term ` `// in the given Series ` `#include <iostream> ` `#include <math.h> ` ` ` `using` `namespace` `std; ` ` ` `// Function to find the nth term ` `// in the given series ` `void` `findNthTerm(` `int` `n) ` `{ ` ` ` `// If input number is even ` ` ` `if` `(n % 2 == 0) { ` ` ` `n = n / 2; ` ` ` `cout << ` `pow` `(3, n - 1) << endl; ` ` ` `} ` ` ` `// If input number is odd ` ` ` `else` `{ ` ` ` `n = (n / 2) + 1; ` ` ` `cout << ` `pow` `(2, n - 1) << endl; ` ` ` `} ` `} ` ` ` `// Driver Code ` `int` `main() ` `{ ` ` ` `int` `N = 4; ` ` ` `findNthTerm(N); ` ` ` ` ` `N = 11; ` ` ` `findNthTerm(N); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to find Nth term ` `// in the given Series ` `import` `java.io.*; ` `import` `java.util.*; ` `import` `java.lang.*; ` ` ` `class` `GFG ` `{ ` `// Function to find the nth term ` `// in the given series ` `static` `void` `findNthTerm(` `int` `n) ` `{ ` ` ` `// If input number is even ` ` ` `if` `(n % ` `2` `== ` `0` `) ` ` ` `{ ` ` ` `n = n / ` `2` `; ` ` ` `System.out.print(Math.pow(` `3` `, n - ` `1` `) + ` `"\n"` `); ` ` ` `} ` ` ` `// If input number is odd ` ` ` `else` ` ` `{ ` ` ` `n = (n / ` `2` `) + ` `1` `; ` ` ` `System.out.print(Math.pow(` `2` `, n - ` `1` `) + ` `"\n"` `); ` ` ` `} ` `} ` ` ` `// Driver Code ` `public` `static` `void` `main(String[] args) ` `{ ` ` ` `int` `N = ` `4` `; ` ` ` `findNthTerm(N); ` ` ` ` ` `N = ` `11` `; ` ` ` `findNthTerm(N); ` ` ` `} ` `} ` ` ` `// This code is contributed ` `// by Akanksha Rai(Abby_akku) ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 program to find Nth term ` `# in the given Series ` ` ` `# Function to find the nth term ` `# in the given series ` `def` `findNthTerm(n): ` ` ` `# If input number is even ` ` ` `if` `n ` `%` `2` `=` `=` `0` `: ` ` ` `n ` `/` `/` `=` `2` ` ` `print` `(` `3` `*` `*` `(n ` `-` `1` `)) ` ` ` `# If input number is odd ` ` ` `else` `: ` ` ` `n ` `=` `(n ` `/` `/` `2` `) ` `+` `1` ` ` `print` `(` `2` `*` `*` `(n ` `-` `1` `)) ` ` ` `# Driver Code ` `if` `__name__` `=` `=` `'__main__'` `: ` ` ` `N ` `=` `4` ` ` `findNthTerm(N) ` ` ` ` ` `N ` `=` `11` ` ` `findNthTerm(N) ` ` ` `# This code is contributed ` `# by vaibhav29498 ` |

*chevron_right*

*filter_none*

## C#

`// C# program to find Nth term ` `// in the given Series ` `using` `System; ` ` ` `class` `GFG ` `{ ` `// Function to find the nth ` `// term in the given series ` `static` `void` `findNthTerm(` `int` `n) ` `{ ` ` ` `// If input number is even ` ` ` `if` `(n % 2 == 0) ` ` ` `{ ` ` ` `n = n / 2; ` ` ` `Console.WriteLine(Math.Pow(3, n - 1)); ` ` ` `} ` ` ` ` ` `// If input number is odd ` ` ` `else` ` ` `{ ` ` ` `n = (n / 2) + 1; ` ` ` `Console.WriteLine(Math.Pow(2, n - 1)); ` ` ` `} ` `} ` ` ` `// Driver Code ` `public` `static` `void` `Main() ` `{ ` ` ` `int` `N = 4; ` ` ` `findNthTerm(N); ` ` ` ` ` `N = 11; ` ` ` `findNthTerm(N); ` `} ` `} ` ` ` `// This code is contributed ` `// by chandan_jnu. ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// php program to find Nth term ` `// in the given Series ` ` ` `// Function to find the nth term ` `// in the given series ` `function` `findNthTerm(` `$n` `) ` `{ ` ` ` `// If input number is even ` ` ` `if` `(` `$n` `% 2 == 0) ` ` ` `{ ` ` ` `$n` `= ` `$n` `/ 2; ` ` ` `echo` `pow(3, ` `$n` `- 1) . ` `"\n"` `; ` ` ` `} ` ` ` `// If input number is odd ` ` ` `else` ` ` `{ ` ` ` `$n` `= (` `$n` `/ 2) + 1; ` ` ` `echo` `pow(2, ` `intval` `(` `$n` `- 1)) . ` `"\n"` `; ` ` ` `} ` `} ` ` ` `// Driver Code ` `$N` `= 4; ` `findNthTerm(` `$N` `); ` ` ` `$N` `= 11; ` `findNthTerm(` `$N` `); ` ` ` `// This code is contributed ` `// by Akanksha Rai(Abby_akku) ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

3 32

## Recommended Posts:

- Find Nth term of the series where each term differs by 6 and 2 alternately
- Program to find the Nth term of the series 3, 7, 13, 21, 31.....
- Program to find Nth term of series 1, 3, 12, 60, 360…
- Program to find the Nth term of series -1, 2, 11, 26, 47......
- Program to find Nth term in the series 0, 0, 2, 1, 4, 2, 6, 3, 8,...
- Program to find Nth term of series 9, 23, 45, 75, 113...
- Program to find Nth term in the series 0, 2, 1, 3, 1, 5, 2, 7, 3,…
- Program to find the Nth term of the series 3, 20, 63, 144, 230, ……
- Program to find the Nth term of series 5, 10, 17, 26, 37, 50, 65, 82, ...
- Program to find the Nth term of series 0, 4, 14, 30, 51, 80, 114, 154, 200, ...
- Program to find the Nth term of the series 0, 14, 40, 78, 124, ...
- Program to find the Nth term of the series 0, 5, 14, 27, 44, ........
- Program to find Nth term of the series 3, 6, 18, 24, ...
- Program to find Nth term of the series 2, 4, 3, 4, 15...
- Program to find Nth term of the series 3, 12, 29, 54, 87, ...
- Program to find Nth term of the series 3 , 5 , 21 , 51 , 95 , ...
- Program to find the Nth term of the series 0, 5, 18, 39, 67, 105, 150, 203, ...
- Program to find Nth term of series 0, 7, 18, 33, 51, 75, 102, 133, .....
- Program to find Nth term of series 0, 10, 30, 60, 99, 150, 210, 280...........
- Program to find Nth term of series 2, 12, 28, 50, 77, 112, 152, 198, .....

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.