human
Count subsequence of length 4 having product of the first three elements equal to the fourth element | Function to find the total number of subsequences satisfying the given criteria.
Stores the count of quadruplets.
Stores the frequency of product of the triplet.
Traverse the given array arr [ ].
Consider arr [ i ] as fourth element of subsequences.
Generate all possible pairs of the array [ 0 , i - 1 ].
Increment the frequency of the triplet.
Return the total count obtained.
Driver Code"
Solution in Python:
assistant
#Here is code to count subsequence of length 4 having product of the first three elements equal to the fourth element and the other steps required.
 def countQuadruples ( A , N ) :
	ans = 0
	freq = { }
	for i in range ( N ) :
		if A [ i ] in freq :
			ans += freq [ A [ i ] ]
		else :
			freq [ A [ i ] ] = 0
		for j in range ( i ) :
			for k in range ( j ) :
				if A [ i ] * A [ j ] * A [ k ] in freq :
					freq [ A [ i ] * A [ j ] * A [ k ] ] += 1
				else :
					freq [ A [ i ] * A [ j ] * A [ k ] ] = 1
	return ans
if __name__ == ' _ _ main _ _ ' :
	arr = [ 10 , 2 , 2 , 7 , 40 , 160 ]
	N = len ( arr )
	print ( countQuadruples ( arr , N ) )