- Related Questions & Answers
- Find minimum positive integer x such that a(x^2) + b(x) + c >= k in C++
- 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++
- Difference between %p and %x in C/C++
- Find a palindromic string B such that given String A is a subsequence of B in C++
- Find Positive Integer Solution for a Given Equation in C++
- Find minimum x such that (x % k) * (x / k) == n in C++
- Find the minimum positive integer such that it is divisible by A and sum of its digits is equal to B in Python
- C++ Program to calculate the value of sin(x) and cos(x)
- Count number of triplets (a, b, c) such that a^2 + b^2 = c^2 and 1<=a<=b<=c<= n in C++
- Find the missing value from the given equation a + b = c in Python
- Count number of solutions of x^2 = 1 (mod p) in given range in C++

- 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

Advertisements