Given the values x, y, p, q of a simple chemical equation of the type:
The task is to find the values of constants b1, b2, b3 such that the equation is balanced on both sides and it must be the reduced form.
Input: x = 2, y = 3, p = 4, q = 5
Output: b1 = 6, b2 = 5, b3 = 3
Input: x = 1, y = 2, p = 3, q = 1
Output: b1 = 3, b2 = 2, b3 = 1
- Check if p % x = 0 and q % y = 0 or not.
- If yes, then simply we can say that
b1 = p / x, b2 = q / y, and b3 = 1
- Else we need to use gcd to compute b1, b2, b3. We need the reduced form so gcd can help with it.
Below is the implementation of the above approach.
6 5 3
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Program to find the Roots of Quadratic equation
- Program to find equation of a plane passing through 3 points
- Program to find number of solutions in Quadratic Equation
- Find the remaining balance after the transaction
- Balance pans using given weights that are powers of a number
- Find the missing value from the given equation a + b = c
- Sum of minimum value of x and y satisfying the equation ax + by = c
- Number of solutions for the equation x + y + z <= n
- Number of integral solutions of the equation x1 + x2 +.... + xN = k
- Sort an array after applying the given equation
- Find the quadratic equation from the given roots
- Print values of 'a' in equation (a+b) <= n and a+b is divisible by x
- Find the number of solutions to the given equation
- Check whether one root of the Quadratic Equation is twice of other or not
- Satisfy the parabola when point (A, B) and the equation is given
- Equation of circle from centre and radius
- Nth Fibonacci number using Pell's equation
- Form the Cubic equation from the given roots
- Check if roots of a Quadratic Equation are reciprocal of each other or not
- Number of non-negative integral solutions of sum equation
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.