- 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

# Find smallest values of x and y such that ax – by = 0 in C++

Suppose we have two values a and b. We have to find x and y, such that ax – by = 0. So if a = 25 and b = 35, then x = 7 and y = 5.

To solve this, we have to calculate the LCM of a and b. LCM of a and b will be the smallest value that can make both sides equal. The LCM can be found using GCD of numbers using this formula −

*LCM (a,b)=(a*b)/GCD(a,b)*

## Example

#include<iostream> #include<algorithm> using namespace std; void getSmallestXY(int a, int b) { int lcm = (a * b) / __gcd(a, b); cout << "x = " << lcm / a << "\ny = " << lcm / b; } int main() { int a = 12, b = 26; getSmallestXY(a, b); }

## Output

x = 13 y = 6

- Related Questions & Answers
- Maximize the value of x + y + z such that ax + by + cz = n in C++
- Find x and y satisfying ax + by = n in C++
- Find the smallest number X such that X! contains at least Y trailing zeros in C++
- Find number of pairs (x, y) in an array such that x^y > y^x in C++
- Find maximum value of x such that n! % (k^x) = 0 in C++
- Find smallest number K such that K % p = 0 and q % K = 0 in C++
- Find a distinct pair (x, y) in given range such that x divides y in C++
- Count of pairs (x, y) in an array such that x < y in C++
- Find larger of x^y and y^x in C++
- Count of all possible values of X such that A % X = B in C++
- Find minimum x such that (x % k) * (x / k) == n in C++
- Find x, y, z that satisfy 2/n = 1/x + 1/y + 1/z in C++
- Find maximum among x^(y^2) or y^(x^2) where x and y are given in C++
- Find Four points such that they form a square whose sides are parallel to x and y axes in Python
- Find Four points such that they form a square whose sides are parallel to x and y axes in C++

Advertisements