human
Count smaller values whose XOR with x is greater than x | Python3 program to find count of values whose XOR with x is greater than x and values are smaller than x.
Initialize result.
Traversing through all bits of x.
If current last bit of x is set then increment count by n . Here n is a power of 2 corresponding to position of bit.
Simultaneously calculate the 2 ^ n.
Replace x with x / 2.
.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to count smaller values whose XOR with x is greater than x and the other steps required.
 def countValues ( x ) :
	count = 0 ;
	n = 1 ;
	while ( x > 0 ) :
		if ( x % 2 == 0 ) :
			count += n ;
		n *= 2 ;
		x /= 2 ;
		x = int ( x ) ;
	return count ;
x = 10 ;
print ( countValues ( x ) ) ;