Reputation: 2595
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.
Upvotes: 1
Views: 1543
Reputation: 241581
This is a linear Diophantine equation. Its solution is very well known. It can be rewritten in the form ex + fy = d
. Find g = gcd(e, f)
. If d = g
then there are infinitely many integral solutions, and these can be found using the extended Euclidean algorithm. Consequently, if d
is merely a multiple of g
, there are infinitely many solutions as well. If d
is not a multiple of g
, there are no solutions.
Upvotes: 10