human
Find Multiples of 2 or 3 or 5 less than or equal to N | Function to count number of multiples of 2 or 3 or 5 less than or equal to N.
As we have to check divisibility by three numbers , So we can implement bit masking.
we check whether jth bit is set or not , if jth bit is set , simply multiply to prod.
check for set bit.
check multiple of product.
Driver code"
Solution in Python:
 ... Write me a code to find Multiples of 2 or 3 or 5 less than or equal to N and the other steps required?
assistant
#Here is code to find Multiples of 2 or 3 or 5 less than or equal to N and the other steps required.
 def countMultiples ( n ) :
	multiple = [ 2 , 3 , 5 ]
	count = 0
	mask = int ( pow ( 2 , 3 ) )
	for i in range ( 1 , mask ) :
		prod = 1
		for j in range ( 3 ) :
			if ( i & ( 1 << j ) ) :
				prod = prod * multiple [ j ]
		if ( bin ( i ) . count ( '1' ) % 2 == 1 ) :
			count = count + n // prod
		else :
			count = count - n // prod
	return count
if __name__ == ' _ _ main _ _ ' :
	n = 10
	print ( countMultiples ( n ) )