Find minimum positive integer x such that a ( x ^ 2 ) + b ( x ) + c >= k | C ++ implementation of the approach ; Function to return the minimum positive integer satisfying the given equation ; Binary search to find the value of x ; Return the answer ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int MinimumX ( int a , int b , int c , int k ) { int x = INT_MAX ; if ( k <= c ) return 0 ; int h = k - c ; int l = 0 ; while ( l <= h ) { int m = ( l + h ) / 2 ; if ( ( a * m * m ) + ( b * m ) > ( k - c ) ) { x = min ( x , m ) ; h = m - 1 ; } else if ( ( a * m * m ) + ( b * m ) < ( k - c ) ) l = m + 1 ; else return m ; } return x ; } int main ( ) { int a = 3 , b = 2 , c = 4 , k = 15 ; cout << MinimumX ( a , b , c , k ) ; return 0 ; }