(Diophantine?) Equations With Multiple Variables

The diophantine equation $ax+by = r$ can be solved if and only if $\gcd(a,b)\mid r$. In that case, the Euclidean algorithm provides an effective way of finding all solutions.

The key to this is that the collection of all possible values of $ax+by$ is precisely the set of all multiples of $\gcd(a,b)$.

Now consider $ax+by+cz = t$. This is equivalent to solving $\gcd(a,b)w + cz = t$, since any solution to the latter yields a solution of the former (by suitable choice of $x$ and $y$ so that $ax+by = \gcd(a,b)w$) and conversely, any solution to $ax+by+cz=t$ yields a solution to $\gcd(a,b)w+cz = t$. Thus, the diophantine equation $ax+by+cz=t$ is equivalent to the diophantine equation $\gcd(a,b)w+cz=t$, which can be solved if and only if $\gcd(\gcd(a,b),c) = \gcd(a,b,c)$ divides $t$.

Similar considerations yield that the diophantine equation $$a_1x_1+a_2x_2+\cdots+a_kx_k = d$$ with $k\gt 0$ has a solution if and only if $\gcd(a_1,a_2,\ldots,a_k)$ divides $d$. When it does, the Euclidean algorithm provides an effective way of finding the solutions.

Gerry Myerson has already addressed the other part of your question.


The 0-1 problem is called the subset sum problem. There is a lot of literature on it. It is known to be NP-complete, which implies that no one knows an algorithm guaranteed to solve it that improves much on brute force.