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
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Balance pans using given weights that are powers of a number
- Find the remaining balance after the transaction
- 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
- Sort an array after applying the given equation
- Given equation of a circle as string, find area
- Find the missing value from the given equation a + b = c
- Find the number of solutions to the given equation
- Equation of circle when three points on the circle are given
- Equation of straight line passing through a given point which bisects it into two equal line segments
- Find the quadratic equation from the given roots
- Satisfy the parabola when point (A, B) and the equation is given
- Count of Fibonacci pairs which satisfy the given equation
- Form the Cubic equation from the given roots
- Find count of numbers from 0 to n which satisfies the given equation for a value K
- Count of unordered pairs (x, y) of Array which satisfy given equation
- Find the equation of plane which passes through two points and parallel to a given axis
- Find the integral roots of a given Cubic equation
- Smallest positive integer X satisfying the given equation