Find n-th term in the series 9, 33, 73,129 ... - GeeksforGeeks

16 Apr, 2021
Given a series 9, 33, 73, 129... Find the n-th term of the series.Examples:  
Input : n = 4
Output : 129 

Input : n = 5
Output : 201
 
The given series has a pattern which is visible after subtracting it from itself after one shift 
S = 9 + 33 + 73 + 129 + ... tn-1 + tn
S =     9 + 33 + 73 + ... tn-2 + tn-1 + tn
———————————————
0 = 9 + (24 + 40 + 56 + ....) - tn 

Since 24 + 40 + 56.. series in A.P with
common difference of 16, we get

 tn = 9 + [((n-1)/2)*(2*24 + (n-1-1)d)] 

On solving this we get 


 tn = 8n2 + 1
Below is the implementation of the above approach:  
C++
Java
Python3
C#
PHP
Javascript
// Program to find n-th element in the// series 9, 33, 73, 128..#include <bits/stdc++.h>using namespace std; // Returns n-th  element of the seriesint series(int n){    return (8 * n * n) + 1;} // driver program to test the above functionint main(){    int n = 5;    cout << series(n);    return 0;}
// Program to find n-th element in the// series 9, 33, 73, 128..import java.io.*; class GFG{         // Returns n-th  element of the series    static int series(int n)    {        return (8 * n * n) + 1;    }         // driver program to test the above    // function    public static void main(String args[])    {        int n = 5;        System.out.println(series(n));    }} /*This code is contributed by Nikita Tiwari.*/
# Python Program to find n-th element# in the series 9, 33, 73, 128... # Returns n-th element of the seriesdef series(n):    print (( 8 * n ** 2) + 1)     # Driver Codeseries(5) # This code is contributed by Abhishek Agrawal.
// C# program to find n-th element in the// series 9, 33, 73, 128..using System; class GFG {     // Returns n-th element of the series    static int series(int n)    {        return (8 * n * n) + 1;    }     // driver function    public static void Main()    {        int n = 5;        Console.WriteLine(series(n));    }} /*This code is contributed by vt_m.*/
<?php// PHP Program to find n-th element// in the series 9, 33, 73, 128.. // Returns n-th element// of the seriesfunction series($n){    return (8 * $n * $n) + 1;} // Driver Code$n = 5;echo(series($n)); // This code is contributed by Ajit.?>
<script> // Program to find n-th element in the// series 9, 33, 73, 128.. // Returns n-th  element of the seriesfunction series(n){    return (8 * n * n) + 1;} // driver program to test the above functionlet n = 5;document.write(series(n)); </script>
Output: 
201
Time complexity: O(1)This article is contributed by Striver. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above. 
jit_t
subhammahato348
series
Mathematical
Mathematical
series
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Program to print prime numbers from 1 to N.
Segment Tree | Set 1 (Sum of given range)
Count all possible paths from top left to bottom right of a mXn matrix
Modular multiplicative inverse
Program to multiply two matrices
Fizz Buzz Implementation
Check if a number is Palindrome
Count ways to reach the n'th stair
Merge two sorted arrays with O(1) extra space
Min Cost Path | DP-6