Related Articles
Find Nth term of the series 1, 6, 18, 40, 75, ….
• Difficulty Level : Easy
• Last Updated : 20 Apr, 2021

Given a number n, the task is to find the n-th term in series 1, 6, 18, 40, 75, …
Example:

Input: N = 2
Output: 6
Explanation:
2nd term = (2^2*(2+1))/2
= 6

Input: N = 5
Output: 75
Explanation:
5th term = (5^2*(5+1))/2
= 75

Approach:

Nth term = (N^2*(N+1))/2

Implementation of the above approach is given below:

## C++

 // CPP code to generate// 'Nth' term of this sequence #include using namespace std; // Function to generate a fixed numberint nthTerm(int N){    int nth = 0;     //(N^2*(N+1))/2    nth = (N * N * (N + 1)) / 2;     return nth;} // Driver Methodint main(){    int N = 5;     cout << nthTerm(N) << endl;     return 0;}

## Java

 // Java code to generate// 'Nth' term of this sequence class GFG {     // Function to generate a fixed number    public static int nthTerm(int N)    {        int nth = 0;         //(N^2*(N+1))/2        nth = (N * N * (N + 1)) / 2;         return nth;    }     // Driver Method    public static void main(String[] args)    {        int N = 5;         System.out.println(nthTerm(N));    }    // This code is contributed by 29AjayKumar}

## Python3

 # python program to find out'Nth' term of this sequence # Function to generate a fixed numberdef nthTerm(N):    nth = 0    nth = (N * N * (N + 1))//2    return nth # Driver codeN = 5print(nthTerm(N)) # This code is contributed by Shrikant13

## C#

 // C# code to generate// 'Nth' term of this sequence using System;public class GFG {     // Function to generate a fixed number    public static int nthTerm(int N)    {        int nth = 0;         //(N^2*(N+1))/2        nth = (N * N * (N + 1)) / 2;         return nth;    }     // Driver Method    public static void Main(string[] args)    {        int N = 5;         Console.WriteLine(nthTerm(N));    }} // This code is contributed by Shrikant13



## Javascript


Output:
75

Time Complexity: O(1)

Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for the language and STL. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.

My Personal Notes arrow_drop_up