Number of days after which tank will become empty | Java code to find number of days after which tank will become empty ; Method returns minimum number of days after which tank will become empty ; Driver code
import java . lang . * ; class GFG { static int minDaysToEmpty ( int C , int l ) { if ( l >= C ) return C ; double eq_root = ( Math . sqrt ( 1 + 8 * ( C - l ) ) - 1 ) / 2 ; return ( int ) ( Math . ceil ( eq_root ) + l ) ; } public static void main ( String [ ] args ) { System . out . println ( minDaysToEmpty ( 5 , 2 ) ) ; System . out . println ( minDaysToEmpty ( 6514683 , 4965 ) ) ; } }