Number of days after which tank will become empty | Method returns minimum number of days after which tank will become empty ; Driver code
function minDaysToEmpty ( C , l ) { if ( l >= C ) return C ; let eq_root = ( Math . sqrt ( 1 + 8 * ( C - l ) ) - 1 ) / 2 ; return ( Math . ceil ( eq_root ) + l ) ; } document . write ( minDaysToEmpty ( 5 , 2 ) + " " ) ; document . write ( minDaysToEmpty ( 6514683 , 4965 ) ) ;