human
Count numbers from a given range that are not divisible by any of the array elements | Function to find the non - multiples till k.
Stores all unique multiples.
Iterate the array.
For finding duplicates only once.
Inserting all multiples into the set.
Returning only the count of numbers that are not divisible by any of the array elements.
Function to count the total values in the range [ L , R ].
Count all values in the range using exclusion principle.
Driver Code.
Function Call"
How can the above be solved in Python?
assistant
#Here is code to count numbers from a given range that are not divisible by any of the array elements and the other steps required.
 def findNonMultiples ( arr , n , k ) :
	multiples = set ( [ ] )
	for i in range ( n ) :
		if ( arr [ i ] not in multiples ) :
			for j in range ( 1 , k // arr [ i ] + 1 ) :
				multiples . add ( arr [ i ] * j )
	return k - len ( multiples )
def countValues ( arr , N , L , R ) :
	return ( findNonMultiples ( arr , N , R ) - findNonMultiples ( arr , N , L - 1 ) )
if __name__ == " _ _ main _ _ " :
	arr = [ 2 , 3 , 4 , 5 , 6 ]
	N = len ( arr )
	L = 1
	R = 20
	print ( countValues ( arr , N , L , R ) )