human
Count of quadruplets from range [ L , R ] having GCD equal to K | Function to return the gcd of a and b.
Function to return the count of quadruplets having gcd = k.
Count the frequency of every possible gcd value in the range.
To store the required count.
Calculate the answer using frequency values.
Return the required count.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to count of quadruplets from range [ L , R ] having GCD equal to K and the other steps required.
 def gcd ( a , b ) :
	if ( b == 0 ) :
		return a ;
	return gcd ( b , a % b ) ;
def countQuadruplets ( l , r , k ) :
	frequency = [ 0 ] * ( r + 1 ) ;
	for i in range ( l , r + 1 ) :
		for j in range ( l , r + 1 ) :
			frequency [ gcd ( i , j ) ] += 1 ;
	answer = 0 ;
	for i in range ( l , r + 1 ) :
		for j in range ( l , r + 1 ) :
			if ( gcd ( i , j ) == k ) :
				answer += ( frequency [ i ] * frequency [ j ] ) ;
	return answer ;
if __name__ == ' _ _ main _ _ ' :
	l , r , k = 1 , 10 , 2 ;
	print ( countQuadruplets ( l , r , k ) ) ;