Minimum number with digits as 4 and 7 only and given sum | Prints minimum number with given digit sum and only allowed digits as 4 and 7. ; Cases where all remaining digits are 4 or 7 ( Remaining sum of digits should be multiple of 4 or 7 ) ; If both 4 s and 7 s are there in digit sum , we subtract a 4. ; Driver code
def findMin ( s ) : NEW_LINE INDENT a , b = 0 , 0 NEW_LINE while ( s > 0 ) : NEW_LINE INDENT if ( s % 7 == 0 ) : NEW_LINE INDENT b += 1 NEW_LINE s -= 7 NEW_LINE DEDENT elif ( s % 4 == 0 ) : NEW_LINE INDENT a += 1 NEW_LINE s -= 4 NEW_LINE DEDENT else : NEW_LINE INDENT a += 1 NEW_LINE s -= 4 NEW_LINE DEDENT DEDENT string = " " NEW_LINE if ( s < 0 ) : NEW_LINE INDENT string = " - 1" NEW_LINE return string NEW_LINE DEDENT string += "4" * a NEW_LINE string += "7" * b NEW_LINE return string NEW_LINE DEDENT print findMin ( 15 ) NEW_LINE