Find the Nth term of the series 1, 3, 7, 15, 31 . . .
Given a positive integer N, the task is to find Nth term of the series:
1, 3, 7, 15, 31, …..
Examples:
Input: N = 5
Output: 31Input: 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 seriesint findTerm(int N){ return pow(2, N) - 1;} // Driver Codeint main(){ int N = 5; cout << findTerm(N); return 0;} |
Output
31
Time Complexity: O(1)
Auxiliary Space: O(1)


 (1).png)