Find N-th term of series 2, 8, 18, 32, 50…
Last Updated :
20 Aug, 2022
Given the series 2, 8, 18, 32, 50…, find the Nth term of the series.
Examples:
Input: N = 1
Output: 2
Input: N = 3
Output: 18
Input: N = 5
Output: 50
Approach:
For finding the nth term we need to find the relation between n and each term.
1st term = 2 = 2*(12) // 2*first perfect square
2nd term = 8 = 2*(22) // 2*second perfect square
3rd term = 18 = 2*(32) // 2*third perfect square
4th term = 32 = 2*(42) // 2*fourth perfect square
.
.
.
.
.
Nth term = 2*(Nth perfect square)
Formula-
TN = 2 * N ^ 2
Illustration-
Input: N = 5
Output: 50
Explanation-
TN = 2 * N ^ 2
= 2* 5 ^ 2
= 2 * 25
= 50
Below is the C++ program to implement the above approach-
C++
#include <iostream>
using namespace std;
int nthTerm( int N)
{
int Nthperfectsquare = N * N;
return 2 * Nthperfectsquare;
}
int main()
{
int N = 5;
cout << nthTerm(N) << endl;
return 0;
}
|
Java
import java.io.*;
class GFG {
static int nthTerm( int N)
{
int Nthperfectsquare = N * N;
return 2 * Nthperfectsquare;
}
public static void main (String[] args) {
int N = 5 ;
System.out.println(nthTerm(N));
}
}
|
Python
def nthTerm(N):
Nthperfectsquare = N * N
return 2 * Nthperfectsquare
if __name__ = = "__main__" :
N = 5
print (nthTerm(N))
|
C#
using System;
public class GFG{
static int nthTerm( int N)
{
int Nthperfectsquare = N * N;
return 2 * Nthperfectsquare;
}
static public void Main (){
int N = 5;
Console.Write(nthTerm(N));
}
}
|
Javascript
<script>
function nthTerm(N)
{
let Nthperfectsquare = N * N;
return 2 * Nthperfectsquare;
}
let N = 5;
document.write(nthTerm(N))
</script>
|
Time Complexity: O(1), since there is no loop or recursion.
Auxiliary Space: O(1), since no extra space has been taken.
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...