human
Write me a code to count elements which divide all numbers in range L and the other steps required given the following:
Count elements which divide all numbers in range L | function to count element Time complexity O ( n ^ 2 ) worst case.
answer for query.
0 based index.
iterate for all elements.
check if the element divides all numbers in range.
no of elements.
if all elements are divisible by a [ i ].
answer for every query.
Driver Code"
Solution in Python:
assistant
#Here is code to count elements which divide all numbers in range L and the other steps required.
 def answerQuery ( a , n , l , r ) :
	count = 0
	l = l - 1
	for i in range ( l , r , 1 ) :
		element = a [ i ]
		divisors = 0
		for j in range ( l , r , 1 ) :
			if ( a [ j ] % a [ i ] == 0 ) :
				divisors += 1
			else :
				break
		if ( divisors == ( r - l ) ) :
			count += 1
	return count
if __name__ == ' _ _ main _ _ ' :
	a = [ 1 , 2 , 3 , 5 ]
	n = len ( a )
	l = 1
	r = 4
	print ( answerQuery ( a , n , l , r ) )
	l = 2
	r = 4
	print ( answerQuery ( a , n , l , r ) )