Find the Nth term of the series 3, 5, 9, 17, 33. . .

Last Updated : 16 Aug, 2022

Given a positive integer N, the task is to find Nth term of the series-

3, 5, 9, 17, 33...till N terms

Examples:

Input: N = 4
Output: 17

Input: N = 3
Output: 9

 

Approach: 

Consider the below example:

Lets say N = 4

The 4th term of the given series is 17, i.e. : 2 ^ 4 + 1 = 16 + 1 = 17

Similarly, lets say N = 3

The 3rd term of the given series is : 2 ^ 3 + 1 = 8 + 1 = 9 (which is correct).

Therefore, we can find out the relation for Nth term of the series using above observations:

1st term = 3 = 21 + 1

2nd term = 22 + 1 = 5

3rd term = 23 + 1 = 9

4th term = 24 + 1 = 17

.

.

Therefore, Nth term can be found out using following relation: 2N + 1

Upon generalising, the relation for Nth term can be represented as:

T_{N} = 2^{N} + 1

Below is the implementation of the above approach-

C++
// C++ program to implement
// the above approach
#include <bits/stdc++.h>
using namespace std;

// Function to return Nth
// term of the series
int findTerm(int N)
{
    return pow(2, N) + 1;
}

// Driver Code
int main()
{
    int N = 6;
    cout << findTerm(N);
    return 0;
}
Java
// Java program to implement
// the above approach
import java.io.*;

class GFG {

  // Function to return Nth
  // term of the series
  static int findTerm(int N)
  {
    return (int)Math.pow(2, N) + 1;
  }

  // Driver Code
  public static void main (String[] args)
  {
    int N = 6;
    System.out.print(findTerm(N));
  }
}

// This code is contributed by Shubham Singh
Python3
# Python program to implement
# the above approach

# Function to return Nth
# term of the series
def findTerm(N):
    return (2 ** N) + 1;

# Driver Code
N = 6;
print(findTerm(N));

# This code is contributed by gfgking
C#
// C# program to implement
// the above approach
using System;
class GFG
{

  // Function to return Nth
  // term of the series
  static int findTerm(int N)
  {
    return (int)Math.Pow(2, N) + 1;
  }

  // Driver Code
  public static void Main()
  {
    int N = 6;
    Console.Write(findTerm(N));
  }
}

// This code is contributed by Samim Hossain Mondal.
JavaScript
    <script>
        // JavaScript program to implement
        // the above approach

        // Function to return Nth
        // term of the series
        const findTerm = (N) => {
            return Math.pow(2, N) + 1;
        }

        // Driver Code
        let N = 6;
        document.write(findTerm(N));

    // This code is contributed by rakeshsahni

    </script>

Output
65

Time Complexity: O(logN) because it using inbuilt pow function
Auxiliary Space: O(1)

Comment