Given an integer **N**, the task is to print the **N ^{th}** term of the series

**9, 45, 243, 1377, 8019, …**

**Examples:**

Input:N = 3Output:243Input:N = 5Output:8019

**Approach:** Let the **N ^{th}** term be

**A**, we can get the

_{n}**N**term easily by observing the series:

^{th}9, 45, 243, 1377, 8019, …

(1^{1}+ 2^{1}) * 3^{1}, (1^{2}+ 2^{2}) * 3^{2}, (1^{3}+ 2^{3}) * 3^{3}, (1^{4}+ 2^{4}) * 3^{4}, …, (1^{n}+ 2^{n}) * 3^{n}

So,A_{n}= (1^{n}+ 2^{n}) * 3^{n}

Below is the implementation of the above approach:

## CPP

`// C++ implementation of the approach` `#include <bits/stdc++.h>` `using` `namespace` `std;` `// Function to return the nth term of the given series` `long` `nthterm(` `int` `n)` `{` ` ` `// nth term` ` ` `int` `An = (` `pow` `(1, n) + ` `pow` `(2, n)) * ` `pow` `(3, n);` ` ` `return` `An;` `}` `// Driver code` `int` `main()` `{` ` ` `int` `n = 3;` ` ` `cout << nthterm(n);` ` ` `return` `0;` `}` |

## Python

`# Python3 implementation of the approach` ` ` `# Function to return the nth term of the given series` `def` `nthterm(n):` ` ` ` ` `# nth term` ` ` `An ` `=` `(` `1` `*` `*` `n ` `+` `2` `*` `*` `n) ` `*` `(` `3` `*` `*` `n)` ` ` ` ` `return` `An;` ` ` ` ` `# Driver code` `n ` `=` `3` `print` `(nthterm(n))` |

## Java

`// Java implementation of the approach` `import` `java.util.*;` `import` `java.lang.*;` `import` `java.io.*;` `public` `class` `GFG {` ` ` `// Function to return the nth term of the given series` ` ` `static` `int` `nthTerm(` `int` `n)` ` ` `{` ` ` `int` `An` ` ` `= ((` `int` `)Math.pow(` `1` `, n) + (` `int` `)Math.pow(` `2` `, n))` ` ` `* (` `int` `)Math.pow(` `3` `, n);` ` ` `return` `An;` ` ` `}` ` ` `// Driver code` ` ` `public` `static` `void` `main(String[] args)` ` ` `{` ` ` `int` `n = ` `3` `;` ` ` `System.out.println(nthTerm(n));` ` ` `}` `}` |

## C#

`// C# implementation of the approach` `using` `System;` `public` `class` `GFG {` ` ` `// Function to return the nth term of the given series` ` ` `static` `int` `nthTerm(` `int` `n)` ` ` `{` ` ` `int` `An` ` ` `= ((` `int` `)Math.Pow(1, n) + (` `int` `)Math.Pow(2, n))` ` ` `* (` `int` `)Math.Pow(3, n);` ` ` `return` `An;` ` ` `}` ` ` `// Driver code` ` ` `public` `static` `void` `Main()` ` ` `{` ` ` `int` `n = 3;` ` ` `Console.WriteLine(nthTerm(n));` ` ` `}` `}` |

## PHP

`<?php` `// PHP implementation of the approach` `// Function to return the nth term of the given series` `function` `nthterm(` `$n` `)` `{` ` ` `$An` `= (pow(1, ` `$n` `) + pow(2, ` `$n` `)) * pow(3, ` `$n` `);` ` ` `// nth term of the given series` ` ` `return` `$An` `;` ` ` `}` ` ` `// Driver code` `$n` `= 3;` `echo` `nthterm(` `$n` `);` `?>` |

## Javascript

`<script>` `// Javascript implementation of the approach` `// Function to return the nth term of the given series` `function` `nthterm(n)` `{` ` ` `// nth term` ` ` `let An = (Math.pow(1, n) + Math.pow(2, n)) * Math.pow(3, n);` ` ` `return` `An;` `}` `// Driver code` `let n = 3;` `document.write(nthterm(n));` `// This code is contributed by subhammahato348.` `</script>` |

**Output:**

243

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.