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
< ? php function findMin ( $ sum ) { $ a = 0 ; $ b = 0 ; while ( $ sum > 0 ) { if ( $ sum % 7 == 0 ) { $ b ++ ; $ sum -= 7 ; } else if ( $ sum % 4 == 0 ) { $ a ++ ; $ sum -= 4 ; } else { $ a ++ ; $ sum -= 4 ; } } if ( $ sum < 0 ) { echo ( " - 1n " ) ; return ; } for ( $ i = 0 ; $ i < $ a ; $ i ++ ) echo ( "4" ) ; for ( $ i = 0 ; $ i < $ b ; $ i ++ ) echo ( "7" ) ; echo ( " STRNEWLINE " ) ; } findMin ( 15 ) ; ? >