The Wayback Machine - https://web.archive.org/web/20220105183157/https://www.geeksforgeeks.org/find-the-nth-term-of-the-series-1-3-7-15-31/
Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Find the Nth term of the series 1, 3, 7, 15, 31 . . .

  • Last Updated : 05 Jan, 2022

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

1, 3, 7, 15, 31, …..

Resolution Days 2022 GeeksforGeeks

Examples:

Input: N = 5
Output: 31



Input: N = 1
Output: 1

Approach:

The sequence is formed by using the following pattern. For any value N-

TN = 2N – 1

Illustration:

Input: N = 5
Output: 31
Explanation:
TN = 2N – 1
     = 25 – 1
     = 32 – 1 
     = 31

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 = 5;
    cout << findTerm(N);
    return 0;
}
Output
31

Time Complexity: O(1)

Auxiliary Space: O(1)

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!