Sum of series 1*1*2! + 2*2*3! + ……..+ n*n*(n+1)!
Given n, we need to find sum of 1*1*2! + 2*2*3! + ……..+ n*n*(n+1)!
Examples:
Input: 1
Output: 2
Input: 3
Output: 242
We may assume that overflow does not happen.
A simple solution is to compute terms one by one and add to result.
An efficient solution is based on direct formula 2 + (n*n + n – 2) * (n + 1)!
The working of formula is based on this post.
C++
// CPP program to find sum of the series. #include <bits/stdc++.h> using namespace std; int factorial(int n) { int res = 1; for (int i = 2; i <= n; i++) res = res * i; return res; } // Function to calculate required series int calculateSeries(int n) { return 2 + (n * n + n - 2) * factorial(n + 1); } // Drivers code int main() { int n = 3; cout << calculateSeries(n); return 0; } |
chevron_right
filter_none
Java
// java program to find sum of the series. import java.io.*; class GFG { static int factorial(int n) { int res = 1; for (int i = 2; i <= n; i++) res = res * i; return res; } // Function to calculate required series static int calculateSeries(int n) { return 2 + (n * n + n - 2) * factorial(n + 1); } // Drivers code public static void main (String[] args) { int n = 3; System.out.println(calculateSeries(n)); } } // This code is contributed by anuj_67. |
chevron_right
filter_none
Python3
# Python program to find sum of # the series. import math def factorial(n): res = 1 i = 2 for i in (n+1): res = res * i return res # Function to calculate required # series def calculateSeries(n): return (2 + (n * n + n - 2) * math.factorial(n + 1)) # Driver code n = 3print(calculateSeries(n)) # This code is contributed by # Prateek bajaj |
chevron_right
filter_none
C#
// C# program to find sum of the series. using System; class GFG { static int factorial(int n) { int res = 1; for (int i = 2; i <= n; i++) res = res * i; return res; } // Function to calculate required series static int calculateSeries(int n) { return 2 + (n * n + n - 2) * factorial(n + 1); } // Driver code public static void Main () { int n = 3; Console.WriteLine(calculateSeries(n)); } } // This code is contributed by anuj_67. |
chevron_right
filter_none
PHP
<?php // PHP program to find sum of the series. function factorial( $n) { $res = 1; for ( $i = 2; $i <= $n; $i++) $res = $res * $i; return $res; } // Function to calculate required series function calculateSeries( $n) { return 2 + ($n * $n + $n - 2) * factorial($n + 1); } // Driver code $n = 3; echo calculateSeries($n); // This code is contributed by anuj_67. ?> |
chevron_right
filter_none
Output:
242
Recommended Posts:
- Sum of Series (n^2-1^2) + 2(n^2-2^2) +....n(n^2-n^2)
- Sum of series 1^2 + 3^2 + 5^2 + . . . + (2*n - 1)^2
- Value of the series (1^3 + 2^3 + 3^3 + ... + n^3) mod 4 for a given n
- Sum of series (n/1) + (n/2) + (n/3) + (n/4) +.......+ (n/n)
- Sum of the series 1 + (1+2) + (1+2+3) + (1+2+3+4) + ...... + (1+2+3+4+...+n)
- Sum of the Series 1 + x/1 + x^2/2 + x^3/3 + .. + x^n/n
- Sum of the series 2 + (2+4) + (2+4+6) + (2+4+6+8) + …… + (2+4+6+8+….+2n)
- Sum of the series 3, 20, 63, 144, ......
- Sum of series 1*1! + 2*2! + ……..+ n*n!
- Sum of the series 2^0 + 2^1 + 2^2 +.....+ 2^n
- Sum of the series 1.2.3 + 2.3.4 + ... + n(n+1)(n+2)
- 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) + . . . . .
- Sum of the series Kn + ( K(n-1) * (K-1)1 ) + ( K(n-2) * (K-1)2 ) + ....... (K-1)n
- Sum of the series 1^1 + 2^2 + 3^3 + ..... + n^n using recursion
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.



