Trying to figure out where to start with this. The equation contains two unknowns and the solution for x or y is always a positive number.
Given a = 123 and b = 55 and c = 5. In this case x = 31 and y = 93 but I don’t know that ahead of time and I’m trying to write a function in C# to solve it.
a - (x + 1) * 96 - (y + 2) + 3104 - c = b
Also if a = 30 and b = 8 and c = 19 then x = 32 and y = 35
so for:
Round 1
function solveX(123, 55, 5) returns 31
function solveY(123, 55, 5) returns 93
Round 2
function solveX(30, 8, 19) returns 32
function solveY(30, 8, 19) returns 35
Any pointers on where to get started would be great.
Thanks.
This is a linear Diophantine equation. Its solution is very well known. It can be rewritten in the form
ex + fy = d. Findg = gcd(e, f). Ifd = gthen there are infinitely many integral solutions, and these can be found using the extended Euclidean algorithm. Consequently, ifdis merely a multiple ofg, there are infinitely many solutions as well. Ifdis not a multiple ofg, there are no solutions.