human
Number of array elements derivable from D after performing certain operations | Function to return gcd of a and b.
Function to Return the number of elements of arr [ ] which can be derived from D by performing ( + A , - A , + B , - B ).
find the gcd of A and B.
counter stores the number of array elements which can be derived from D.
arr [ i ] can be derived from D only if | arr [ i ] - D | is divisible by gcd of A and B.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to number of array elements derivable from D after performing certain operations and the other steps required.
 def gcd ( a , b ) :
	if ( a == 0 ) :
		return b
	return gcd ( b % a , a ) ;
def findPossibleDerivables ( arr , n , D , A , B ) :
	gcdAB = gcd ( A , B )
	counter = 0
	for i in range ( n ) :
		if ( ( abs ( arr [ i ] - D ) % gcdAB ) == 0 ) :
			counter += 1
	return counter
if __name__ == " _ _ main _ _ " :
	arr = [ 1 , 2 , 3 , 4 , 7 , 13 ]
	n = len ( arr )
	D , A , B = 5 , 4 , 2
	print ( findPossibleDerivables ( arr , n , D , A , B ) )
	a = [ 1 , 2 , 3 ]
	n = len ( a )
	D , A , B = 6 , 3 , 2
	print ( findPossibleDerivables ( a , n , D , A , B ) )