human
Sum of series formed by difference between product and sum of N natural numbers | Recursive Function to calculate the sum upto Nth term.
If N - th term is calculated.
Update multi to store product upto K.
Update add to store sum upto K.
Update prevSum to store sum upto K.
Proceed to next K.
Function to calculate and return the Sum upto Nth term.
Recursive Function.
Driver code"
Solution in Python:
assistant
#Here is code to sum of series formed by difference between product and sum of N natural numbers and the other steps required.
 def seriesSumUtil ( k , n , prevSum , multi , add ) :
	if ( k == n + 1 ) :
		return prevSum ;
	multi = multi * k ;
	add = add + k ;
	prevSum = prevSum + multi - add ;
	return seriesSumUtil ( k + 1 , n , prevSum , multi , add ) ;
def seriesSum ( n ) :
	if ( n == 1 ) :
		return 0 ;
	prevSum = 0 ;
	multi = 1 ;
	add = 1 ;
	return seriesSumUtil ( 2 , n , prevSum , multi , add ) ;
if __name__ == ' _ _ main _ _ ' :
	N = 5 ;
	print ( seriesSum ( N ) ) ;