human
Count the number of subsequences of length k having equal LCM and HCF | Returns factorial of n.
Returns nCr for the given values of r and n.
Map to store the frequencies of each elements.
Loop to store the frequencies of elements in the map.
Using nCR formula to calculate the number of subsequences of a given length.
Driver Code.
Function calling"
Solution in Python:
assistant
#Here is code to count the number of subsequences of length k having equal LCM and HCF and the other steps required.
 def fact ( n ) :
	res = 1
	for i in range ( 2 , n + 1 ) :
		res = res * i
	return res
def nCr ( n , r ) :
	return fact ( n ) // ( fact ( r ) * fact ( n - r ) )
def number_of_subsequences ( arr , k , n ) :
	s = 0
	m = dict ( )
	for i in arr :
		m [ i ] = m . get ( i , 0 ) + 1
	for j in m :
		s = s + nCr ( m [ j ] , k )
	return s
arr = [ 1 , 1 , 1 , 1 , 2 , 2 , 2 ]
k = 2
n = len ( arr )
print ( number_of_subsequences ( arr , k , n ) )