# Program to find Nth term of series 9, 23, 45, 75, 113…

Given a number N, the task is to find the Nth term in the given series:

`9, 23, 45, 75, 113, 159......`

Examples:

```Input: 4
Output: 113
Explanation:
For N = 4
Nth term = ( 2 * N + 3 )*( 2 * N + 3 ) - 2 * N
= ( 2 * 4 + 3 )*( 2 * 4 + 3 ) - 2 * 4
= 113

Input: 10
Output: 509```

Approach:
The Nth term of the given series can be generalised as:

`Nth term of the series : ( 2 * N + 3 )*( 2 * N + 3 ) - 2 * N`

Below is the implementation of the above problem:
Program:

## C++

 `// CPP program to find N-th term of the series:` `// 9, 23, 45, 75, 113...`   `#include ` `using` `namespace` `std;`   `// calculate Nth term of series` `int` `nthTerm(``int` `N)` `{` `    ``return` `(2 * N + 3) * (2 * N + 3) - 2 * N;` `}`   `// Driver Function` `int` `main()` `{`   `    ``// Get the value of N` `    ``int` `N = 4;`   `    ``// Find the Nth term` `    ``// and print it` `    ``cout << nthTerm(N);`   `    ``return` `0;` `}`

## Java

 `// Java program to find ` `// N-th term of the series: ` `// 9, 23, 45, 75, 113... `   `class` `GFG ` `{`   `// calculate Nth term of series ` `static` `int` `nthTerm(``int` `N) ` `{ ` `    ``return` `(``2` `* N + ``3``) * ` `           ``(``2` `* N + ``3``) - ``2` `* N; ` `} `   `// Driver code` `public` `static` `void` `main(String[] args)` `{` `    `  `    ``// Get the value of N ` `    ``int` `N = ``4``; ` `    `  `    ``// Find the Nth term ` `    ``// and print it ` `    ``System.out.println(nthTerm(N));` `}` `}`   `// This code is contributed by Bilal`

## Python3

 `# Python program to find ` `# N-th term of the series: ` `# 9, 23, 45, 75, 113... ` `def` `nthTerm(N): ` `    `  `    ``# calculate Nth term of series` `    ``return` `((``2` `*` `N ``+` `3``) ``*` `            ``(``2` `*` `N ``+` `3``) ``-` `2` `*` `N);`   `# Driver Code `   `# Get the value of N ` `n ``=` `4`   `# Find the Nth term ` `# and print it ` `print``(nthTerm(n)) `   `# This code is contributed by Bilal`

## C#

 `// C# program to find ` `// N-th term of the series: ` `// 9, 23, 45, 75, 113... ` `using` `System;`   `class` `GFG ` `{`   `// calculate Nth term of series ` `static` `int` `nthTerm(``int` `N) ` `{ ` `    ``return` `(2 * N + 3) * ` `           ``(2 * N + 3) - 2 * N; ` `} `   `// Driver code` `public` `static` `void` `Main()` `{` `    `  `    ``// Get the value of N ` `    ``int` `N = 4; ` `    `  `    ``// Find the Nth term ` `    ``// and print it ` `    ``Console.WriteLine(nthTerm(N));` `}` `}`   `// This code is contributed` `// by Akanksha Rai(Abby_akku)`

## PHP

 ``

## Javascript

 ``

Output:

`113`

Time Complexity: O(1)

Space Complexity: O(1) since using constant variables

Feeling lost in the world of random DSA topics, wasting time without progress? It's time for a change! Join our DSA course, where we'll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 geeks!

Previous
Next