Skip to content
Related Articles
Find Nth term of the series 2, 3, 10, 15, 26….
• Last Updated : 18 Mar, 2021

Given a number N, the task is to find the Nth term in series 2, 3, 10, 15, 26….
Example:

```Input: N = 2
Output: 3
2nd term = (2*2)-1
= 3

Input: N = 5
Output: 26
5th term = (5*5)+1
= 26```

Approach:

• Nth number of the series is obtained by
1. Squaring the number itself.
2. If the number is odd, add 1 to the squared number. And, subtract 1 if the number is even
• Since the starting number of the series is 2
1st term = 2
2nd term = (2 * 2) – 1 = 3
3rd term = (3 * 3) + 1 = 10
4th term = (4 * 4) – 1 = 15
5th term = (5 * 5) + 1 = 26
and so on….

• In general, Nth number is obtained by formula: •

Below is the implementation of the above approach:

## C++

 `// C++ program to find Nth term``// of the series 2, 3, 10, 15, 26....` `#include ``using` `namespace` `std;` `// Function to find Nth term``int` `nthTerm(``int` `N)``{``    ``int` `nth = 0;` `    ``// Nth term``    ``if` `(N % 2 == 1)``        ``nth = (N * N) + 1;``    ``else``        ``nth = (N * N) - 1;` `    ``return` `nth;``}` `// Driver Method``int` `main()``{``    ``int` `N = 5;` `    ``cout << nthTerm(N) << endl;` `    ``return` `0;``}`

## Java

 `// Java program to find Nth term``// of the series 2, 3, 10, 15, 26....``class` `GFG``{` `// Function to find Nth term``static` `int` `nthTerm(``int` `N)``{``    ``int` `nth = ``0``;` `    ``// Nth term``    ``if` `(N % ``2` `== ``1``)``        ``nth = (N * N) + ``1``;``    ``else``        ``nth = (N * N) - ``1``;` `    ``return` `nth;``}` `// Driver code``public` `static` `void` `main(String[] args)``{``    ``int` `N = ``5``;` `    ``System.out.print(nthTerm(N) +``"\n"``);` `}``}` `// This code is contributed by Rajput-Ji`

## Python3

 `# Python3 program to find Nth term``# of the series 2, 3, 10, 15, 26....` `# Function to find Nth term``def` `nthTerm(N) :``    ``nth ``=` `0``;` `    ``# Nth term``    ``if` `(N ``%` `2` `=``=` `1``) :``        ``nth ``=` `(N ``*` `N) ``+` `1``;``    ``else` `:``        ``nth ``=` `(N ``*` `N) ``-` `1``;` `    ``return` `nth;` `# Driver Method``if` `__name__ ``=``=` `"__main__"` `:``    ``N ``=` `5``;``    ``print``(nthTerm(N)) ;` `# This code is contributed by AnkitRai01`

## C#

 `// C# program to find Nth term``// of the series 2, 3, 10, 15, 26....``using` `System;` `class` `GFG``{` `// Function to find Nth term``static` `int` `nthTerm(``int` `N)``{``    ``int` `nth = 0;` `    ``// Nth term``    ``if` `(N % 2 == 1)``        ``nth = (N * N) + 1;``    ``else``        ``nth = (N * N) - 1;` `    ``return` `nth;``}` `// Driver code``public` `static` `void` `Main(String[] args)``{``    ``int` `N = 5;` `    ``Console.Write(nthTerm(N) +``"\n"``);``}``}` `// This code is contributed by PrinciRaj1992`

## Javascript

 ``
Output:
`26`

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

In case you wish to attend live classes with industry experts, please refer DSA Live Classes

My Personal Notes arrow_drop_up