Find the nth term of the series 0, 8, 64, 216, 512, . . . - GeeksforGeeks

06 Apr, 2021
Given an integer N, the task is to find the Nth term of the following series:  
0, 8, 64, 216, 512, 1000, 1728, . . .  
Examples:  
Input: N = 6 Output: 1000Input: N = 5 Output: 512  
 
Approach:  
Given series 0, 8, 64, 216, 512, 1000, 1728, ... can also be written as 0 * (02), 2 * (22), 4 * (42), 6 * (62), 8 * (82), 10 * (102), ...
Observe that 0, 2, 4, 6, 10, ... is in AP and the nth term of this series can be found using the formula term = a1 + (n – 1) * d where a1 is the first term, n is the term position and d is the common difference.
To get the term in the original series, term = term * (term2) i.e. term3.
Finally print the term.
Below is the implementation of the above approach: 
C++
Java
Python3
C#
PHP
Javascript
// C++ implementation of the approach#include <bits/stdc++.h>using namespace std; // Function to return the nth term of the given serieslong term(int n){    // Common difference    int d = 2;     // First term    int a1 = 0;     // nth term    int An = a1 + (n - 1) * d;     // nth term of the given series    An = pow(An, 3);    return An;} // Driver codeint main(){    int n = 5;     cout << term(n);     return 0;}
// Java implementation of the approachimport java.util.*;import java.lang.*;import java.io.*; public class GFG {     // Function to return the nth term of the given series    static int nthTerm(int n)    {         // Common difference and first term        int d = 2, a1 = 0;         // nth term        int An = a1 + (n - 1) * d;         // nth term of the given series        return (int)Math.pow(An, 3);    }     // Driver code    public static void main(String[] args)    {        int n = 5;        System.out.println(nthTerm(n));    }}
# Python3 implementation of the approach # Function to return the nth term of the given seriesdef term(n):         # Common difference    d = 2         # First term    a1 = 0         # nth term    An = a1 +(n-1)*d         # nth term of the given series    An = An**3    return An;      # Driver coden = 5print(term(n))
// C# implementation of the approachusing System;public class GFG {     // Function to return the nth term of the given series    static int nthTerm(int n)    {         // Common difference and first term        int d = 2, a1 = 0;         // nth term        int An = a1 + (n - 1) * d;         // nth term of the given series        return (int)Math.Pow(An, 3);    }     // Driver code    public static void Main()    {        int n = 5;        Console. WriteLine(nthTerm(n));    }}// This code is contributed by Mutual singh.
<?php// PHP implementation of the approach // Function to return the nth term of the given seriesfunction term($n) {      // Common difference    $d = 2;     // First term    $a1 = 0;     // nth term    $An=$a1+($n-1)*$d;     // nth term of the given series    return pow($An, 3);                      }    // Driver code $n = 5;echo term($n); ?>
<script> // javascript implementation of the approach // Function to return the nth term of the given seriesfunction term(n) {      // Common difference    let d = 2;     // First term    let a1 = 0;     // nth term    An=a1+(n-1)*d;     // nth term of the given series    return Math.pow(An, 3);                      }    // Driver code let n = 5;document.write( term(n));  // This code is contributed by sravan kumar </script>
512
 
Code_Mech
sravankumar8128
arithmetic progression
series
Mathematical
Mathematical
series
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Merge two sorted arrays
Prime Numbers
Modulo Operator (%) in C/C++ with Examples
Program for Decimal to Binary Conversion
Find all factors of a natural number | Set 1
Program to find sum of elements in a given array
Modulo 10^9+7 (1000000007)
The Knight's tour problem | Backtracking-1
Program for factorial of a number
Operators in C / C++