- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

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.

If A = 2 and B = 4 then answer will be 2.

- 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)

#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; }

When you compile and execute above program. It generates following output −

Answer = 2

- Related Questions & Answers
- Find minimum positive integer x such that a(x^2) + b(x) + c >= k in C++
- Count of all possible values of X such that A % X = B in C++
- Construct SLR (1) parsing table for the following grammar\nS → x A y |x B y |x A z\nA → q s | q\nB → q
- Minimum positive integer divisible by C and is not in range [A, B] in C++
- Find multiple of x closest to or a ^ b (a raised to power b) in C++
- Print values of ‘a’ in equation (a+b) <= n and a+b is divisible by x
- Maximum positive integer divisible by C and is in the range [A, B] in C++
- Find the multiple of x which is closest to a^b in C++
- Larger of a^b or b^a in C++
- Difference between %p and %x in C/C++
- Find Positive Integer Solution for a Given Equation in C++
- Find a palindromic string B such that given String A is a subsequence of B in C++
- Find FIRST & FOLLOW for the following Grammar.\nS → A a A | B b B\nA → b B\nB → ε
- Find minimum x such that (x % k) * (x / k) == n in C++
- Construct Quadruples, Triples, and Indirect Triples for the expression\n-(a + b) * (c + d) - (a + b + c)

Advertisements