Check if it is possible to survive on Island | Function to find the minimum $days ; If we can not buy at least a week supply of food during the first week OR We can not buy a day supply of food on the first day then we can 't survive. ; If we can survive then we can buy ceil ( A / N ) times where A is total units of food required . ; Driver code
< ? php function survival ( $ S , $ N , $ M ) { if ( ( ( $ N * 6 ) < ( $ M * 7 ) && $ S > 6 ) $ M > $ N ) echo " No " ; else { $ days = ( $ M * $ S ) / $ N ; if ( ( ( $ M * $ S ) % $ N ) != 0 ) $ days ++ ; echo " Yes ▁ " , floor ( $ days ) ; } } $ S = 10 ; $ N = 16 ; $ M = 2 ; survival ( $ S , $ N , $ M ) ; ? >