Find the sum of first n terms of the given series:

3, 20, 63, 144, .....

**Examples:**

Input : n = 2 Output : 23 Input : n =4 Output : 230

**Approach**:

First, we have to find the general term (Tn) of the given series.

series can we written in the following way also: (3 * 1^2), (5 * 2^2), (7 * 3^2), (9 * 4^2), .......up t n terms Tn = (General term of series 3, 5, 7, 9 ....) X (General term of series 1^2, 2^2, 3^2, 4^2 ....) Tn = (3 + (n-1) * 2) X ( n^2 ) Tn = 2*n^3 + n^2

We can write the sum of the series in the following ways:

Sn = 3 + 20 + 63 + 144 + ........up to the n terms

Sn = 2 * (sum of n terms of n^3 ) + (sum of n terms of n^2)

Following are the formulas of sum of n terms of n^3 and n^2 :

Below is the implementation of the above approach:

## C++

`// C++ program to find the sum of n terms ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` `int` `calculateSum(` `int` `n) ` `{ ` ` ` `return` `(2 * ` `pow` `((n * (n + 1) / 2), 2)) + ` ` ` `((n * (n + 1) * (2 * n + 1)) / 6); ` `} ` `int` `main() ` `{ ` ` ` `int` `n = 4; ` ` ` `cout << ` `"Sum = "` `<< calculateSum(n) << endl; ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to find the sum of n terms ` `import` `java.io.*; ` ` ` `public` `class` `GFG ` `{ ` ` ` `static` `int` `calculateSum(` `int` `n) ` ` ` `{ ` ` ` `return` `(` `int` `)((` `2` `* Math.pow((n * (n + ` `1` `) / ` `2` `), ` `2` `))) + ` ` ` `((n * (n + ` `1` `) * (` `2` `* n + ` `1` `)) / ` `6` `); ` ` ` `} ` ` ` ` ` `public` `static` `void` `main (String[] args) { ` ` ` ` ` `int` `n = ` `4` `; ` ` ` `System.out.println(` `"Sum = "` `+ calculateSum(n)); ` ` ` ` ` `} ` `} ` `// This code is contributed by Raj ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 program to find the sum of n terms ` ` ` `def` `calculateSum(n): ` ` ` `return` `((` `2` `*` `(n ` `*` `(n ` `+` `1` `) ` `/` `2` `)` `*` `*` `2` `) ` `+` ` ` `((n ` `*` `(n ` `+` `1` `) ` `*` `(` `2` `*` `n ` `+` `1` `)) ` `/` `6` `)) ` ` ` `#Driver code ` ` ` `n ` `=` `4` `print` `(` `"Sum ="` `,calculateSum(n)) ` ` ` `# this code is contributed by Shashank_Sharma ` |

*chevron_right*

*filter_none*

## C#

`// C# program to find the sum of n terms ` `using` `System; ` ` ` `class` `GFG ` `{ ` `static` `int` `calculateSum(` `int` `n) ` `{ ` ` ` `return` `(` `int` `)((2 * Math.Pow((n * (n + 1) / 2), 2))) + ` ` ` `((n * (n + 1) * (2 * n + 1)) / 6); ` `} ` ` ` `// Driver Code ` `public` `static` `void` `Main () ` `{ ` ` ` `int` `n = 4; ` ` ` `Console.WriteLine(` `"Sum = "` `+ calculateSum(n)); ` `} ` `} ` ` ` `// This code is contributed by anuj_67 ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP program to find the ` `// sum of n terms ` ` ` `function` `calculateSum(` `$n` `) ` `{ ` ` ` `return` `(2 * pow((` `$n` `* (` `$n` `+ 1) / 2), 2)) + ` ` ` `((` `$n` `* (` `$n` `+ 1) * (2 * ` `$n` `+ 1)) / 6); ` `} ` ` ` `// Driver Code ` `$n` `= 4; ` `echo` `"Sum = "` `, calculateSum(` `$n` `); ` ` ` `// This code is contributed by ash264 ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

Sum = 230

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Program to find the Nth term of the series 3, 20, 63, 144, 230, ……
- Check if a number is formed by Concatenation of 1, 14 or 144 only
- Sum of sum-series of first N Natural numbers
- Sum of series formed by difference between product and sum of N natural numbers
- Program to find sum of series 1 + 1/2 + 1/3 + 1/4 + .. + 1/n
- Efficient Program to Compute Sum of Series 1/1! + 1/2! + 1/3! + 1/4! + .. + 1/n!
- Find the sum of all the terms in the n-th row of the given series
- Program for sum of geometric series
- Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! +.......+ n/n!
- Java Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! +.......+ n/n!
- Program for sum of arithmetic series
- Series with largest GCD and sum equals to n
- Program to find Sum of a Series a^1/1! + a^2/2! + a^3/3! + a^4/4! +…….+ a^n/n!
- Sum of the series 1 + (1+3) + (1+3+5) + (1+3+5+7) + …… + (1+3+5+7+…+(2n-1))
- Sum of the Series 1/(1*2) + 1/(2*3) + 1/(3*4) + 1/(4*5) + . . . . .
- Find the sum of the series 1+11+111+1111+..... upto n terms
- Sum of the Series 1 + x/1 + x^2/2 + x^3/3 + .. + x^n/n
- Sum of the series 1, 3, 6, 10... (Triangular Numbers)
- Sum of the series 1 + (1+2) + (1+2+3) + (1+2+3+4) + ...... + (1+2+3+4+...+n)
- Program to get the Sum of series: 1 - x^2/2! + x^4/4! -.... upto nth term

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.