human
XOR of array elements whose modular inverse with a given number exists | Function to return the gcd of a & b.
Base Case.
Recursively calculate GCD.
Function to print the Bitwise XOR of elements of arr [ ] if gcd ( arr [ i ] , M ) is 1.
Initialize xor.
Traversing the array.
GCD of M and arr [ i ].
If GCD is 1 , update xor.
Print xor.
Drive Code.
Given array arr [ ].
Given number M.
Size of the array.
Function Call"
How can the above be solved in Python?
 Write me a code to xOR of array elements whose modular inverse with a given number exists and the other steps required?
assistant
#Here is code to xOR of array elements whose modular inverse with a given number exists and the other steps required.
 def gcd ( a , b ) :
	if ( a == 0 ) :
		return b
	return gcd ( b % a , a )
def countInverse ( arr , N , M ) :
	XOR = 0
	for i in range ( 0 , N ) :
		gcdOfMandelement = gcd ( M , arr [ i ] )
		if ( gcdOfMandelement == 1 ) :
			XOR = XOR ^ arr [ i ]
	print ( XOR )
if __name__ == ' _ _ main _ _ ' :
	arr = [ 1 , 2 , 3 ]
	M = 4
	N = len ( arr )
	countInverse ( arr , N , M )