# C++ program to find n-th term in the series 9, 33, 73,129 …

C++Server Side ProgrammingProgramming

In this problem, we are given an integer N. The task is to find n-th term in series 9, 33, 73, 129....

Let’s take an example to understand the problem,

## Input

N = 4

## Output

129

## Explanation

The series upto nth term is 9, 33, 73, 129...

## Solution Approach

The solution to the problem lies in finding the nth term of the series. We will find it mathematically and then apply the general term formula to our program.

First let’s subtract the series by shifting it by one.

Sum = 9 + 33 + 73 + … + t(n-1) + t(n)
- Sum = 9 + 33 + 73 + …. + t(n-1) + t(n)

0 = 9 + ((33- 9) + (73 - 33) + … + (tn) - t(n-1)) - t(n)
t(n) = 9 + (24 + 40 + 56 + …. )

24 + 40 + 56 + …. is an A.P. series with common difference 16.

This makes the general term,

t(n) = 9 + [ ((n-1)/2)*(2*(24) + (n-1-1)*16) ]

$$t(n)=9+[\left(\frac{n-1}{2}\right)*((2*24)+(n-2)*16)]$$ $$t(n)=9+[\left(\frac{n-1}{2}\right)*((2*24)+(n-2)*8)]$$

t(n) = 9 + [(n - 1) * ((24) + (n - 2) * 8]

t(n) = 9 + [(n - 1) * ((24) + 8n - 16]

t(n) = 9 + [(n - 1) * (8 + 8n]

t(n) = 9 + 8 * [(n - 1) * (n + 1)]

t(n) = 9 + 8 * [n2 - 12]

t(n) = 9 + 8 * n2 - 8

t(n) = 8 * n2 + 1

Program to illustrate the working of our solution,

## Example

Live Demo

#include <iostream>
using namespace std;
int findNthTerm(int n) {
return (8*n*n) + 1 ;
}
int main(){
int n = 12;
cout<<"The series is 9, 33, 73, 129...\n";
cout<<n<<"th term of the series is "<<findNthTerm(n);
return 0;
}

## Output

The series is 9, 33, 73, 129...
12th term of the series is 1153
Published on 13-Mar-2021 12:17:45
Advertisements