Find n-th term of series 2, 10, 30, 68, 130 …
Given a series 2, 10, 30, 68, 130 … Identify the pattern in the series and find the nth value in the series. Indices are starting from 1 . 1 <= n <= 200
Examples:
Input : n = 12 Output : 1740 Input : n = 200 Output : 8000200
If observed carefully, pattern of the series can be noticed as n^3 + n.
Below is the implementation of above approach:
C++
// C++ program to find n-th value #include <bits/stdc++.h> using namespace std; // Function to find nth term int findValueAtX(int n) { return (n * n * n) + n; } // drivers code int main() { cout << findValueAtX(10) << endl; cout << findValueAtX(2) << endl; return 0; } |
chevron_right
filter_none
Java
// Java program to find n-th value import java.io.*; class GFG { // Function to find nth term static int findValueAtX(int n) { return (n * n * n) + n; } // driver code public static void main(String[] args) { System.out.println(findValueAtX(10)); System.out.println(findValueAtX(2)); } } // This code is contributed by vt_m. |
chevron_right
filter_none
Python3
# Python3 program to find n-th value # Function to find nth term def findValueAtX(n): return (n * n * n) + n # Driver Code print(findValueAtX(10)) print(findValueAtX(2)) # This code is contributed by Azkia Anam. |
chevron_right
filter_none
C#
// C# program to find n-th value using System; class GFG { // Function to find nth term static int findValueAtX(int n) { return (n * n * n) + n; } // driver code public static void Main() { Console.WriteLine(findValueAtX(10)); Console.WriteLine(findValueAtX(2)); } } |
chevron_right
filter_none
PHP
<?php // PHP program to // find n-th value // Function to find nth term function findValueAtX($n) { return ($n * $n * $n) + $n; } // Driver Code echo findValueAtX(10),"\n"; echo findValueAtX(2); // This code is contributed by anuj_67. ?> |
chevron_right
filter_none
Output:
1010 10
Recommended Posts:
- Find Nth term of the series 1, 1, 2, 6, 24...
- Find Nth term of the series 1, 8, 54, 384...
- Find nth term of the series 5 2 13 41
- Find nth Term of the Series 1 2 2 4 4 4 4 8 8 8 8 8 8 8 8 ...
- Find n-th term of series 1, 3, 6, 10, 15, 21...
- Find Nth term of series 1, 4, 15, 72, 420...
- Find Nth term of the series 1, 5, 32, 288 ...
- Find Nth term of the series 1, 6, 18, 40, 75, ....
- Find Nth term of the series 5, 13, 25, 41, 61...
- Find Nth term of the series 3, 14, 39, 84...
- Find sum of Series with n-th term as n^2 - (n-1)^2
- Find n-th term in series 1 2 2 3 3 3 4 4 4 4....
- Find the Nth term of the series 1 + 2 + 6 + 15 + 31 + 56 + ...
- Find the nth term of the series 0, 8, 64, 216, 512, . . .
- Find the Nth term of the series 2 + 6 + 13 + 23 + . . .
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : vt_m



