human
Give me a code to count the combination of 4 s and / or 5 s required to make each Array element 0 and the other steps required given the following:
Count the combination of 4 s and / or 5 s required to make each Array element 0 | Function to print the count of the combination of 4 or 5 required to make the arr [ i ] for each 0 < i < N.
Vector to store the answer.
Iterate in the range [ 0 , N - 1 ].
Initialize sum to store the count of numbers and cnt for the current factor of 4.
Iterate in the range [ 0 , arr [ i ] ] with increment of 4.
Check if arr [ i ] - j ( the current factor of 4 ) is divisible by 5 or not.
If sum is not maximum then answer is found.
Finally , print the required answer.
Given Input.
Function Call"
Solution in Python:
assistant
#Here is code to count the combination of 4 s and / or 5 s required to make each Array element 0 and the other steps required.
 def sumOfCombinationOf4OR5 ( arr , N ) :
	ans = [ - 1 for i in range ( N ) ]
	for i in range ( N ) :
		if ( arr [ i ] < 4 ) :
			continue
		sum = 10 ** 9
		cnt = 0
		for j in range ( 0 , arr [ i ] + 1 , 4 ) :
			if ( ( arr [ i ] - j ) % 5 == 0 ) :
				sum = min ( sum , cnt + ( arr [ i ] - j ) // 5 )
			cnt += 1
		if ( sum != 10 ** 9 ) :
			ans [ i ] = sum
	for num in ans :
		print ( num , end = " ▁ " )
arr = [ 7 , 15 , 17 , 22 ]
N = len ( arr )
sumOfCombinationOf4OR5 ( arr , N )