Find the sum of first N terms of the series 2*3*5, 3*5*7, 4*7*9, …

Given an integer N, the task is to find the sum of first N terms of the series:

(2 * 3 * 5), (3 * 5 * 7), (4 * 7 * 9), …

Examples:

Input: N = 3
Output: 387
S3 = (2 * 3 * 5) + (3 * 5 * 7) + (4 * 7 * 9) = 30 + 105 + 252 = 387

Input: N = 5
Output: 1740

Approach: Let the Nth term of the series be Tn. Sum of the series can be easily found by observing the Nth term of the series:

Tn = {nth term of 2, 3, 4, …} * {nth term of 3, 5, 7, …} * {nth term of 5, 7, 9, …}
Tn = (n + 1) * (2 * n + 1) * (2* n + 3)
Tn = 4n3 + 12n2 + 11n + 3

Sum(Sn) of first n terms can be found by

Sn = ΣTn
Sn = Σ[4n3 + 12n2 + 11n + 3]
Sn = (n / 2) * [2n3 + 12n2 + 25n + 21]

Below is the implementation of the above approach:

C++

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to find sum of the
// first n terms of the given series
#include <bits/stdc++.h>
using namespace std;
  
// Function to return the sum of the
// first n terms of the given series
int calSum(int n)
{
    // As described in the approach
    return (n * (2 * n * n * n + 12 * n * n + 25 * n + 21)) / 2;
}
  
// Driver code
int main()
{
    int n = 3;
    cout << calSum(n);
    return 0;
}

chevron_right


Python

filter_none

edit
close

play_arrow

link
brightness_4
code

# C++ program to find sum of the
# first n terms of the given series
  
# Function to return the sum of the 
# first n terms of the given series
def calSum(n): 
      
    # As described in the approach
    return (n*(2 * n*n * n + 12 * n*n + 25 * n + 21))/2
  
# Driver Code 
n = 3
print(calSum(n)) 

chevron_right


Java

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to find sum of the
// first n terms of the given series
class GFG {
  
    // Function to return the sum of the
    // first n terms of the given series
    static int calSum(int n)
    {
  
        // As described in the approach
        return (n * (2 * n * n * n + 12 * n * n + 25 * n + 21)) / 2;
    }
  
    // Driver Code
    public static void main(String args[])
    {
        int n = 3;
        System.out.println(calSum(n));
    }
}

chevron_right


C#

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to find sum of the
// first n terms of the given series
using System;
  
class GFG {
  
    // Function to return the sum of the
    // first n terms of the given series
    static int calSum(int n)
    {
  
        // As described in the approach
        return (n * (2 * n * n * n + 12 * n * n + 25 * n + 21)) / 2;
    }
  
    // Driver code
    static public void Main()
    {
        int n = 3;
        Console.WriteLine(calSum(n));
    }
}

chevron_right


PHP

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php 
// PHP script to find sum of the
// first n terms of the given series
  
// Function to return the sum of the 
// first n terms of the given series
function calculateSum($n
{
      
    // As described in the approach
    return ($n*(2*$n*$n*$n+12*$n*$n+25*$n+21))/2; 
  
// Driver code
$n = 3;
echo calculateSum($n); 
  
?>

chevron_right


Output:

387


My Personal Notes arrow_drop_up

Data science |Machine learning|Programming facebook -https//wwwfacebookcom/profilephpid=100002787011326

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.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.