
- 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
Minimum positive integer value possible of X for given A and B in X = P*A + Q*B in C++
Problem statement
Given values of A and B, find the minimum positive integer value of X that can be achieved in the equation X = P*A + Q*B, Here P and Q can be zero or any positive or negative integer.
Example
If A = 2 and B = 4 then answer will be 2.
Algorithm
- We need to find P and Q such that P*A > P*B and P*A – P*B is minimum positive integer.
- This problem can be easily solved by calculating GCD of both numbers)
Example
#include <iostream> using namespace std; int getGcd(int a, int b) { if (a == 0) { return b; } return getGcd(b % a, a); } int main() { cout << "Answer = " << getGcd(2, 4) << endl; return 0; }
Output
When you compile and execute above program. It generates following output −
Answer = 2
- Related Articles
- Find minimum positive integer x such that a(x^2) + b(x) + c >= k in C++
- Solve the following pairs of linear equations: (i) \( p x+q y=p-q \)$q x-p y=p+q$(ii) \( a x+b y=c \)$b x+a y=1+c$,b>(iii) \( \frac{x}{a}-\frac{y}{b}=0 \)$a x+b y=a^{2}+b^{2}$(iv) \( (a-b) x+(a+b) y=a^{2}-2 a b-b^{2} \)$(a+b)(x+y)=a^{2}+b^{2}$(v) \( 152 x-378 y=-74 \)$-378 x+152 y=-604$.
- If roots of equation $x^2+x+1=0$ are $a,\ b$ and roots of $x^2+px+q=0$ are $\frac{a}{b},\ \frac{b}{a}$; then find the value of $p+q$.
- Minimum positive integer divisible by C and is not in range [A, B] in C++
- For which values of \( a \) and \( b \), are the zeroes of \( q(x)=x^{3}+2 x^{2}+a \) also the zeroes of the polynomial \( p(x)=x^{5}-x^{4}-4 x^{3}+3 x^{2}+3 x+b \) ? Which zeroes of \( p(x) \) are not the zeroes of \( q(x) \) ?
- Find the value of $(x-a)^3 + (x-b)^3 + (x-c)^3 - 3 (x-a)(x-b)(x-c)$ if $a+b+c = 3x$
- Count of all possible values of X such that A % X = B in C++
- Find the numerical value of \( P: Q \) where \( \mathrm{P}=\left(\frac{x^{m}}{x^{n}}\right)^{m+n-l} \times\left(\frac{x^{n}}{x^{l}}\right)^{n+l-m} \times\left(\frac{x^{l}}{x^{m}}\right)^{l+m-n} \) and\( \mathrm{Q}=\left(x^{1 /(a-b)}\right)^{1 /(a-c)} \times\left(x^{1 /(b-c)}\right)^{1 /(b-a)} \times\left(x^{1 /(c-a)}\right)^{1 /(c-b)} \)where \( a, b, c \) being all different.A. \( 1: 2 \)B. \( 2: 1 \)C. \( 1: 1 \)D. None of these
- Given that \( \frac{4 p+9 q}{p}=\frac{5 q}{p-q} \) and \( p \) and \( q \) are both positive. The value of $\frac{p}{q}$ is
- Answer the following and justify:What will the quotient and remainder be on division of \( a x^{2}+b x+c \) by \( p x^{3}+q x^{2}+r x+s, p ≠ 0 ? \)
- In \( \triangle A B C, \angle A \) is obtuse, \( P B \perp A C, \) and \( Q C \perp A B \). Prove that \( A B \times A Q=A C \times A P \).
- In each of the following, find the value of $k$ for which the given value is a solution of the given equation: $x^2-x(a+b)+k=0$, $x=a$
- In \( \triangle A B C, \angle A \) is obtuse, \( P B \perp A C, \) and \( Q C \perp A B \). Prove that \( B C^{2}=\left(A C \times C P +A B \times B Q\right) \).
- Show that:\( \left[\left\{\frac{x^{a(a-b)}}{x^{a(a+b)}}\right\} \p\left\{\frac{x^{b(b-a)}}{x^{b(b+a)}}\right\}\right]^{a+b}=1 \)
- Simplify:\( \left(\frac{x^{a+b}}{x^{c}}\right)^{a-b}\left(\frac{x^{b+c}}{x^{a}}\right)^{b-c}\left(\frac{x^{c+a}}{x^{b}}\right)^{c-a} \)

Advertisements