# How to solve 700 = 7x + 6y for a range of values?

Last time I did any maths was A-Level (some time ago!).

This is a programming/layout problem where I need to display 7 items across a page, with 6 gaps between them. I have a fixed width, but need to determine values of x and y that are integers where x > y.

This 'feels' like something I could plot on a graph, hence solve with calculus but I need a pointer in the right direction. Ideally I'd like to solve it programatically but I need an understanding of how to solve it first. Further down the line, I'd like to be able to vary the number of items to get different values.

Thanks

-

First, find one solution. Here you can say 700 = 7*100 + 6*0, or 700 = 700*1 = 700*(7-6) = 7*700 + 6*(-700).

One you have one solution $(x_1,y_1)$, another solution $(x_2,y_2)$ has to satisfy $7x_1+6y_1 = 700 = 7x_2+6y_2$, so $7(x_1-x_2) + 6(y_1-y_2) = 0$.

Here this means that $7(x_1-x_2) = 6(y_2-y_1)$. Since 6 and 7 are coprime, this number is a multiple of 42, so $7(x_1-x_2) = 6(y_2-y_1) = 42k$.

Now you get $x_2 = x_1 - 6k, y_2 = y_1+7k$, and that gives you the set of solutions $S = \{(100-6k, 0+7k), k \in \mathbb{Z}\}$. If you only want to have solutions with positive $0<y<x$, this means you get constraints on $k$ : $0 < k$ and $k < 100/13$, which means $k \in \{1, 2, \ldots 7 \}$

Edit :

If you want to solve $a = nx + (n-1)y$, since $n$ and $n-1$ are coprime, the same method works : start with the particular solution $a = a*1 = n*a + (n-1)*(-a)$, so $(x=a, y= -a)$. the solutions in $\mathbb{Z}^2$ are $\{(x=a-k(n-1), y= kn-a)), k \in \mathbb{Z}\}$. Then you write the constraints $0<y<x$ in terms of $k$ and you get $a/n < k < 2a/(2n-1)$

-
Thanks Chandok, I'm looking to solve this programatically. Any ideas how I might set this up? Ultimately I want to solve the equation totalwidth = n(imagewidth) + (n-1)(gapwidth). I will always know totalwidth and n, just need to determine the values of imagewidth and gapwidth. – Jeepstone Feb 25 '11 at 10:08
have you looked at this question math.stackexchange.com/questions/20906/… ? – mercio Feb 25 '11 at 10:09

If you want integer solutions, you have a linear diophantine equation. You can start by observing that $y$ must be a multiple of $7$, then simplify the equation using this.

-