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
def sumOfCombinationOf4OR5 ( arr , N ) : NEW_LINE INDENT ans = [ - 1 for i in range ( N ) ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( arr [ i ] < 4 ) : NEW_LINE INDENT continue NEW_LINE DEDENT sum = 10 ** 9 NEW_LINE cnt = 0 NEW_LINE for j in range ( 0 , arr [ i ] + 1 , 4 ) : NEW_LINE INDENT if ( ( arr [ i ] - j ) % 5 == 0 ) : NEW_LINE INDENT sum = min ( sum , cnt + ( arr [ i ] - j ) // 5 ) NEW_LINE DEDENT cnt += 1 NEW_LINE DEDENT if ( sum != 10 ** 9 ) : NEW_LINE INDENT ans [ i ] = sum NEW_LINE DEDENT DEDENT for num in ans : NEW_LINE INDENT print ( num , end = " ▁ " ) NEW_LINE DEDENT DEDENT arr = [ 7 , 15 , 17 , 22 ] NEW_LINE N = len ( arr ) NEW_LINE sumOfCombinationOf4OR5 ( arr , N ) NEW_LINE