Find the Nth term of the series 9, 45, 243,1377

Given an integer N, the task is to print the Nth term of the series 9, 45, 243, 1377, 8019, …

Examples:

Input: N = 3
Output: 243

Input: N = 5
Output: 8019



Approach: Let the Nth term be An, we can get the Nth term easily by observing the series:

9, 45, 243, 1377, 8019, …
(11 + 21) * 31, (12 + 22) * 32, (13 + 23) * 33, (14 + 24) * 34, …, (1n + 2n) * 3n
So, An = (1n + 2n) * 3n

Below is the implementation of the above approach:

CPP

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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;
}

chevron_right


Python

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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)) 

chevron_right


Java

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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));
    }
}

chevron_right


C#

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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));
    }
}

chevron_right


PHP

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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); 
?> 

chevron_right


Output:

243


My Personal Notes arrow_drop_up

Data science |Machine learning|Programming

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.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.