Finding all integer solutions to a linear equation that lie in a particular region

44 Views Asked by At

I want to find all $(x,y,z)$ satisfying $z=x+ay,a>0$ where $0\le x\le X,0\le y \le Y, 0 \le z \le Z$. Additionally, $Z>X$. An expression for the number of all such $(x,y,z)$ tuples is also needed.

Any help/pointers will be greatly appreciated.

Edit: All numbers in the problem are integers.

1

There are 1 best solutions below

0
On

Hint:

Plot in 2D the rectangle (real values) $0 \le x \le X$, $0 \le y \le Y$.

Then plot the (real) line $x+ay=Z$.

You get, in general, a triangle, a trapetium, or a rectangle minus a trapetium/triangle ($Z+1 \le x+ay$).

In the second case, translate and flip the trapetium/triangle to have the right corner at the origin, and compute its (integer) points (for instance by Pick theorem).

You have all the elements to compute the valid $(x,y)$ couples and thus $(x,y,z)$ triples.