
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Find minimum positive integer x such that a(x^2) + b(x) + c >= k in C++
Suppose we have four integers a, b, c and k. We have to find the minimum positive value x, such that the following equation satisfies −
𝑎𝑥2+𝑏𝑥+𝑐 ≥𝑘
If a = 3, b = 4, c = 5 and k = 6, then output will be 1
To solve this, we will use the bisection approach. The lower limit will be 0 since x has to be a minimum positive integer.
Example
#include<iostream> using namespace std; int getMinX(int a, int b, int c, int k) { int x = INT8_MAX; if (k <= c) return 0; int right = k - c; int left = 0; while (left <= right) { int mid = (left + right) / 2; int val = (a * mid * mid) + (b * mid); if (val > (k - c)) { x = min(x, mid); right = mid - 1; } else if (val < (k - c)) left = mid + 1; else return mid; } return x; } int main() { int a = 3, b = 2, c = 4, k = 15; cout << "Minimum value of x is: " << getMinX(a, b, c, k); }
Output −
Minimum value of x is: 2
- Related Articles
- Find minimum x such that (x % k) * (x / k) == n in C++
- Minimum positive integer value possible of X for given A and B in X = P*A + Q*B in C++
- Find maximum value of x such that n! % (k^x) = 0 in C++
- If \( a \) and \( b \) are distinct positive primes such that \( \sqrt[3]{a^{6} b^{-4}}=a^{x} b^{2 y} \), find \( x \) and \( y \).
- Find the value of \( k \), if \( x-1 \) is a factor of \( p(x) \) in each of the following cases:(i) \( p(x)=x^{2}+x+k \)(ii) \( p(x)=2 x^{2}+k x+\sqrt{2} \)(iii) \( p(x)=k x^{2}-\sqrt{2} x+1 \)(iv) \( p(x)=k x^{2}-3 x+k \)
- If a and b are different positive primes such that\( (a+b)^{-1}\left(a^{-1}+b^{-1}\right)=a^{x} b^{y} \), find \( x+y+2 . \)
- Find \( k \) so that \( x^{2}+2 x+k \) is a factor of \( 2 x^{4}+x^{3}-14 x^{2}+5 x+6 \). Also find all the zeroes of the two polynomials.
- Show that:\( \left(\frac{x^{a^{2}+b^{2}}}{x^{a b}}\right)^{a+b}\left(\frac{x^{b^{2}+c^{2}}}{x^{b c}}\right)^{b+c}\left(\frac{x^{c^{2}+a^{2}}}{x^{a c}}\right)^{a+c}= x^{2\left(a^{3}+b^{3}+c^{3}\right)} \)
- Find \( \mathrm{k} \) so that \( x^{2}+2 x+k \) is a factor of \( 2 x^{4}+x^{3}-14 x^{2}+5 x+6 \). Also, find all the zeroes of the two polynomials.
- Polynomial \( f(x)=x^{2}-5 x+k \) has zeroes \( \alpha \) and \( \beta \) such that \( \alpha-\beta=1 . \) Find the value of \( 4 k \).
- Prove that:\( \left(\frac{x^{a}}{x^{b}}\right)^{a^{2}+a b+b^{2}} \times\left(\frac{x^{b}}{x^{c}}\right)^{b^{2}+b c+c^{2}} \times\left(\frac{x^{c}}{x^{a}}\right)^{c^{2}+c a+a^{2}}=1 \)
- Prove that:\( \left(\frac{x^{a}}{x^{-b}}\right)^{a^{2}-a b+b^{2}} \times\left(\frac{x^{b}}{x^{-c}}\right)^{b^{2}-b c+c^{2}} \times\left(\frac{x^{c}}{x^{-a}}\right)^{c^{2}-c a+a^{2}}=1 \)
- Count of all possible values of X such that A % X = B in C++
- Find number of pairs (x, y) in an array such that x^y > y^x in C++
- Fill in the blank $(x+a)(x+b)=x^2$+______ $x+a b$

Advertisements