Find the Nth term of the series 5, 13, 37, 109, 325, . . .
Given a positive integer N. The task is to find Nth term of the series 5, 13, 37, 109, 325, …..
Examples:
Attention reader! Don’t stop learning now. Get hold of all the important mathematical concepts for competitive programming with the Essential Maths for CP Course at a student-friendly price. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
Input: N = 5
Output: 325
Explanation: From the sequence it can be seen that the 5th term is 325Input: N = 1
Output: 5
Explanation: The 1st term of the given sequence is 5
Approach: The sequence formed by using the following patter. For any value N
TN = 4 * 3N – 1 + N
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 calcNum(int N) { return 4 * pow(3, N - 1) + 1; } // Driver Codeint main(){ int N = 5; cout << calcNum(N); return 0;} |
325
Time Complexity: O(1)
Auxiliary Space: O(1)

