Open In App

Program to find the Nth term of series 0, 4, 14, 30, 51, 80, 114, 154, 200, …

Last Updated : 28 Aug, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Given a number N. The task is to write a program to find the Nth term of the below series:
 

0, 4, 14, 30, 51, 80, 114, 154, 200, …(N Terms)


Examples: 
 

Input: N = 4
Output: 82
For N = 4
4th Term = ( 4 * 4 - 2 * 4 + 2) 
         = 10

Input: N = 10
Output: 122


 


Approach: The generalized Nth term of this series: 
 

nth\: Term\: of\: the\: series\: = n^2-2n+2 


Below is the required implementation: 
 

C++

// CPP program to find the N-th term of the series:
// 5, 10, 17, 26, 37, 50, 65, 82, ...
#include <iostream>
#include <math.h>
using namespace std;
 
// calculate Nth term of series
int nthTerm(int n)
{
    return pow(n, 2) - 2 * n + 2;
}
 
// Driver Function
int main()
{
    int N = 4;
 
    cout << nthTerm(N);
 
    return 0;
}

                    

Java

// Java program to find the N-th term of the series:
// 5, 10, 17, 26, 37, 50, 65, 82, ...
import java.util.*;
 
class solution
{
 
// calculate Nth term of series
static int nthTerm(int n)
{
     
    //return the total sum
    return (int)Math.pow(n, 2) - 2 * n + 2;
}
 
//Driver function
public static void main(String arr[])
{
    int N = 4;
 
    System.out.println(nthTerm(N));
 
}
 
}

                    

Python3

# Python3 program to find the N-th
# term of the series:
# 0, 4, 14, 30, 51, 80, 114, 154, 200, …
 
# from math lib. import everything
from math import *
 
# calculate Nth term of series
def nthTerm(n) :
     
    return pow(n, 2) - 2 * n + 2
 
         
# Driver code    
if __name__ == "__main__" :
 
    N = 4
    print(nthTerm(N))
 
# This code is contributed by
# ANKITRAI1

                    

C#

// C# program to find the
// N-th term of the series:
// 5, 10, 17, 26, 37, 50, 65, 82, ...
using System;
 
class GFG
{
 
// calculate Nth term of series
public static int nthTerm(int n)
{
 
    // return the total sum
    return (int)Math.Pow(n, 2) -
                    2 * n + 2;
}
 
// Driver Code
public static void Main(string[] arr)
{
    int N = 4;
 
    Console.WriteLine(nthTerm(N));
}
}
 
// This code is contributed
// by Shrikant13

                    

PHP

<?php
// PHP program to find the
// N-th term of the series:
// 5, 10, 17, 26, 37, 50, 65, 82, ...
 
// calculate Nth term of series
function nthTerm($n)
{
    return pow($n, 2) - 2 * $n + 2;
}
 
// Driver Code
$N = 4;
 
echo nthTerm($N);
 
// This code is contributed
// by ChitraNayal
?>

                    

Javascript

<script>
// JavaScript program to find the N-th term of the series:
// 5, 10, 17, 26, 37, 50, 65, 82, ...
 
// calculate Nth term of series
function nthTerm( n)
{
    return Math.pow(n, 2) - 2 * n + 2;
}
// Driver code
 
    let N = 4;
   document.write( nthTerm(N) );
 
// This code contributed by aashish1995
 
</script>

                    

Output: 
10

 

Time Complexity: O(1), since there is no loop or recursion.

Space Complexity: O(1) since using constant variables
 



Previous Article
Next Article

Similar Reads

Program to find Nth term of series 0, 9, 22, 39, 60, 85, 114, 147, .....
Given a number N. The task is to write a program to find the Nth term of the below series: 0, 9, 22, 39, 60, 85, 114, 147.....(N Terms) Examples: Input: N = 4 Output: 39 For N = 4 4th Term = ( 2 * 4 * 4 + 3 * 4 - 5) = 39 Input: N = 10 Output: 224 Approach: The generalized Nth term of this series: [Tex]nth\: Term\: of\: the\: series\: = 2*n^2+3*n-5[
3 min read
Nth term where K+1th term is product of Kth term with difference of max and min digit of Kth term
Given two integers N and D, the task is to find the value of F(N) where the value of F(1) is D, where F(K) is given as: [Tex]F(K+1) = F(K) * (Max_{Digit}(F(K)) - Min_{Digit}(F(K)))[/Tex] Examples: Input: N = 3, D = 487 Output: 15584 Explanation: As F(1) = 487, F(2) = 487 * (maxDigit(487) - minDigit(487)) = 487 * 4 = 1948 F(3) = 1948 * (maxDigit(194
6 min read
Find Nth term of the series where each term differs by 6 and 2 alternately
Given a number N, the task is to find the Nth term of the series where each term differs by 6 and 2 alternately.Examples: Input: N = 6 Output: 24 Explanation: The Nth term is 0 + 6 + 2 + 6 + 2 + 6 + 2 = 24Input: N = 3 Output: 14 Explanation: The Nth term is 0 + 6 + 2 + 6 = 14 Naive Approach: The idea is to iterate from 1 with an increment of 6 and
7 min read
Find the Nth term of the series where each term f[i] = f[i - 1] - f[i - 2]
Given three integers X, Y and N, the task is to find the Nth term of the series f[i] = f[i - 1] - f[i - 2], i &gt; 1 where f[0] = X and f[1] = Y.Examples: Input: X = 2, Y = 3, N = 3 Output: -2 The series will be 2 3 1 -2 -3 -1 2 and f[3] = -2Input: X = 3, Y = 7, N = 8 Output: 4 Approach: An important observation here is that there will be atmost 6
10 min read
Program to find Nth term of series 1, 3, 12, 60, 360…
Given a number N. The task is to write a program to find the Nth term in the below series: 1, 3, 12, 60, 360… Examples: Input: 2 Output: 3 Input: 4 Output: 60 Approach: The idea is to first find the factorial of the number (N+1), that is (N+1)!Now, the N-th term in the above series will be: N-th term = (N+1)!/2 Below is the implementation of the ab
5 min read
Program to find the Nth term of series -1, 2, 11, 26, 47......
Given a number N, the task is to find the Nth term of this series: -1, 2, 11, 26, 47, 74, ..... Examples: Input: 3 Output: 11 Explanation: when N = 3 Nth term = ( (3 * N * N) - (6 * N) + 2 ) = ( (3 * 3 * 3) - (6 * 3) + 2 ) = 11 Input: 9 Output: 191 Approach: The Nth term of the given series can be generalised as: Nth term of the series : ( (3 * N *
3 min read
Program to find Nth term in the series 0, 0, 2, 1, 4, 2, 6, 3, 8,...
Given a number N. The task is to write a program to find the N-th term in the below series: 0, 0, 2, 1, 4, 2, 6, 3, 8, 4, 10, 5, 12, 6, 14, 7, 16, 8,..... Examples: Input : N = 10 Output : 4 Input : N = 7 Output : 6 On observing carefully, you will find that the series is a mixture of 2 series: Terms at odd positions in the given series form the se
5 min read
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
4 min read
Program to find Nth term in the series 0, 2, 1, 3, 1, 5, 2, 7, 3,…
Given a number N. The task is to write a program to find the N-th term in the below series: 0, 2, 1, 3, 1, 5, 2, 7, 3, … Examples: Input: N = 5 Output: 1 Input: N = 10 Output: 11 When we look carefully at the series, we find that the series is a mixture of 2 series: Terms at odd positions in the given series forms fibonacci series.Terms at even pos
8 min read
Program to find the Nth term of the series 3, 20, 63, 144, 230, ……
Given a series and a number N. The task is to find the Nth term of the given series: 3, 20, 63, 144, 230 ..... Examples: Input: N = 4 Output: 144 When n = 4 nth term = 2 ( n * n * n ) + n * n = 2 ( 4 * 4 * 4 ) + 4 * 4 = 144 Input: N = 10 Output: 2100 Approach: We can find the general term (Tn) of the given series. [Tex]series\: can\: be\: written\:
3 min read