Number of days after which tank will become empty | C / C ++ 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 to test above methods
#include <bits/stdc++.h> NEW_LINE using namespace std ; int minDaysToEmpty ( int C , int l ) { if ( l >= C ) return C ; double eq_root = ( std :: sqrt ( 1 + 8 * ( C - l ) ) - 1 ) / 2 ; return std :: ceil ( eq_root ) + l ; } int main ( ) { cout << minDaysToEmpty ( 5 , 2 ) << endl ; cout << minDaysToEmpty ( 6514683 , 4965 ) << endl ; return 0 ; }