Answer the question
In order to leave comments, you need to log in
Is there a way to solve an equation of the form ax+by+cz = d in integers?
Is it possible to solve an equation of the form: ax+by+cz = d in integers in some known way? We consider the case when there is definitely a solution. All coefficients are integers. There can be more than 3 variables (up to 10).
Answer the question
In order to leave comments, you need to log in
There are two identical paths, one has a stroke-dashoffset set for its entire length:
https://css-tricks.com/svg-line-animation-works/
For two variables, the problem is solved through the extended Euclid algorithm .
Solve iteratively by adding new variables. Here you got the first k variables so their sum with the coefficients is equal to the GCD() coefficients. Let this gcd(a1,a2,... ak) = d. Now solve the equation d*x + a(k+1)y = gcd(d,a(k+1)) using the same algorithm. y will be the desired value of the last variable, and all previous values must be multiplied by the x value.
At the end you have found the GCD of all coefficients and you can check that the right side is divisible by it. if not, there is no solution. If it is divided, then it is necessary to multiply all the variables by the result of the division.
Yes, there is also a special effect that GCD does not work with negative numbers. It is necessary to change the signs of the coefficients, remember this and at the end change the signs of the variables back.
Solution in O(n log M), where n is the number of variables, M is the maximum value of the coefficients.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question