I want to find all possible solution for the equation $x+2y+3z = V$, where $0\le x+y+z\le 5$, and $0\le x,y,z$.

37 Views Asked by At

Using modular arithmetic, I have derived that for the equation $x + 2y + 3z= v$ has solutions for any pair of integers, $k$ and $m$, where $x = \frac{-v - 2v_3 + 3v_2}{6} + k - m$, $y = -2x -3m - v_3$, and $z = 2k + v_2 - x$, where $v_2$ and $v_3$ denote the remainder of $v/2$ and $v/3$ respectively.

I think I have also successfuly derived parameters for $m$ to return only values where $0 \leq x+y+z \leq 5$. If $\frac{v-v_3}{3} - 5 \leq m \leq \frac{v-v_3}{3}$, then $0 \leq x+y+z \leq 5$. However, I cannot seem to get the same result for $k$.I have tried using the condition that $0 \leq x,y,z$ to get the same bounds for $k$, but I cannot produce an inequality that bounds it in a way such that I am getting the maximum and minimum $k$ values necessary to find every solution where $0 \leq x+y+z \leq 5$.

For context, I need this equation for a nested for loop. The idea is to run through all variations of $k$ and $m$, and pick out the solutions to the Diophantine equation. Based on what I have seen from running tests, it appears as though it isn't possible to set for-loop parameters that only pick out relevant values for $x, y,$ and $z$, so the idea is to find parameters for $k$ that provably find all solutions to this equation as efficiently as possible.

Edit: Nvm I figured it out.