human
Sum of pairwise products | Efficient Python3 program to find sum of given series ..
Sum of multiples of 1 is 1 * ( 1 + 2 + . . ).
Adding sum of multiples of numbers other than 1 , starting from 2..
Subtract previous number from current multiple ..
For example , for 2 , we get sum as ( 2 + 3 + 4 + ... . ) * 2.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to sum of pairwise products and the other steps required.
 def findSum ( n ) :
	multiTerms = n * ( n + 1 ) // 2
	sm = multiTerms
	for i in range ( 2 , n + 1 ) :
		multiTerms = multiTerms - ( i - 1 )
		sm = sm + multiTerms * i
	return sm
n = 5
print ( findSum ( n ) )