Integer solution to linear equation

2.6k Views Asked by At

I need to find a good configuration for my computational kernel, which forces me to find some integer solutions to the following simple equation:

$a \cdot x - b \cdot y = c$,

where $a$, $b$ and $c$ are constant positive integers, and $x$ and $y$ are my unknown, that I need to also be positive integers.

I thought I could solve this using the Diophantine solution, but I'm not sure how to proceed due to one of the addends to be negative.

What is the best way to find all solutions to such an equation?

1

There are 1 best solutions below

0
On

We see that the line of solutions given any $a, b, c$ is modelled by the linear equation $$y = \frac{ax-c}{b}$$ (whose equation can be obtained by performing elementary algebra)

All you need to do is solve this equation given your $a,b,c$ such that the solutions are integers.

In order for $y$ to be a positive integer, we require that $ax-c$ be an integer (which is true given our circumstances) and $b$ be an integer (also true) such that $(ax-c) \mod b = 0$ (their dividend is an integer).

Since $b$ is a positive integer, and since in order for $y$ to be a positive integer, $(ax - c) / b$ must be positive, then $ax-c$ must be positive so that $y$ is positive. This means we require

$$ax > c$$

and thus $$x > a/c$$

So, to calculate for $x$ given $a,b,c$, we test all positive integers which satisfy

$$(ax-c) \mod b = 0$$ $$x > a/c$$

And if these requirements are met, then $x$ is a solution and therefore you may plug in to obtain $y$.