human
Counts 1 s that can be obtained in an Array by performing given operations | Function to count total number of 1 s in array by performing given operations.
Stores count of 1 s in the array by performing the operations.
Iterate over the range [ 1 , N ].
Flip all array elements whose index is multiple of i.
Update arr [ i ].
Traverse the array.
If current element is 1.
Update cntOnes.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to counts 1 s that can be obtained in an Array by performing given operations and the other steps required.
 def cntOnesArrWithGivenOp ( arr , N ) :
	cntOnes = 0
	for i in range ( 1 , N + 1 ) :
		for j in range ( i - 1 , N , i ) :
			arr [ j ] = 1 if arr [ j ] == 0 else 0
	for i in range ( N ) :
		if ( arr [ i ] == 1 ) :
			cntOnes += 1
	return cntOnes
if __name__ == ' _ _ main _ _ ' :
	arr = [ 0 , 0 , 0 , 0 , 0 ]
	N = len ( arr )
	print ( cntOnesArrWithGivenOp ( arr , N ) )