human
Calculate the Sum of GCD over all subarrays | Utility function to calculate sum of gcd of all sub - arrays ..
Fixing the starting index of a subarray.
Fixing the ending index of a subarray.
Finding the GCD of this subarray.
Adding this GCD in our sum.
Driver Code"
How can the above be solved in Python?
 What is a code to calculate the Sum of GCD over all subarrays and the other steps required?
assistant
#Here is code to calculate the Sum of GCD over all subarrays and the other steps required.
 def findGCDSum ( n , a ) :
	GCDSum = 0 ;
	tempGCD = 0 ;
	for i in range ( n ) :
		for j in range ( i , n ) :
			tempGCD = 0 ;
			for k in range ( i , j + 1 ) :
				tempGCD = __gcd ( tempGCD , a [ k ] ) ;
			GCDSum += tempGCD ;
	return GCDSum ;
def __gcd ( a , b ) :
	return a if ( b == 0 ) else __gcd ( b , a % b ) ;
if __name__ == ' _ _ main _ _ ' :
	n = 5 ;
	a = [ 1 , 2 , 3 , 4 , 5 ] ;
	totalSum = findGCDSum ( n , a ) ;
	print ( totalSum ) ;