Find $A = x - y + z$ if $3x + 5y + 7z = 29$ and $x , y , z \in \mathbb{Z}^+$ I've found the answer by trial and error $(x = 4 , y=2,z=1) \Rightarrow$ $A = 3$. I tried to solve it using modular arithmetic but it didn't work .
$$3x + 5y + 7z = 29 $$
$$ 3x + 5y+7z \equiv 29  \mod 3$$
$$ 2y +z \equiv 2 \mod 3 $$
$$ y= -k , z=2k + 2$$
putting $ y= -k , z=2k + 2$ to original equation leads to $x = -3k + 5$ . Then $A = -3k+5 +k +2k+2 = 7$ . What's wrong about my answer? 
 A: Starting from your 3.rd line. For some integer $t$ we have $$2y+z-2 = 3t\implies z = 2+3t-2y$$
So $$3x+5y+7(2+3t-2y) = 29\implies 3x = 15-21t+9y$$
so $$x = 5-7t+3y$$
thus $$A = 5-7t+3y -y+2+3t-2y=-4t+7$$
Since $2y+z\geq 3\implies 3t+2\geq 3\implies t\geq 1$
Since $z\leq 4$ and $y\leq 5$ we get $3t+2\leq 14$ so $t\leq 4$. 
A: Since you have only asked about what has gone wrong through your working, I will limit myself to that. 
You have found $y=-k$ and $z=2k+2$
Now $x>0,y>0,z>0$, that means $y=-k>0$ implies that $k<0$
$k<0\implies 2k<0\implies 2k+2<2 \implies z<2\implies z=1$ as $z\in \mathbb{Z}^+$
But that is a contradiction as $z$ is even in your case$(z=2k+2)$!!!

In short, $2y+z\equiv 2  \mod3$ have other solutions too, like $z=3,y=1$
A: Trial and error may be not that bad if one reduces the values for $x,y,z$ by a bit modular arithmetic:


*

*$3x + 5y + 7z = 29 \Rightarrow 3x+5y \equiv 1 \mod 7$

*Since $x , y , z \in \mathbb{Z}^+ \Rightarrow 3x+5y \in \{8,15,22\}\Rightarrow x=4, y = 2 \Rightarrow z=1$
A: You don't get $z = 2k + 2$. you get $z \equiv 2k + 2 \mod 3$.
Or $z = 2k + 2 + 3M$.
Plugging that into the equation we get
$3x -5k + 2k + 14k + 14 + 21M = 29$ so
$3x = -9k + 15 + 21M$ or 
$x = -3k + 5 + M$ for some integer $M$. As $M$ can be any integer that is pretty useless but let's continue.
Plugging $x = -3k + 5 + M; y = -k; z = 2k +   2 + 3M$ we get:
$A = -3k + 5 + M +k + 2k +2 + 3M  = 7 + 4M$
In this case it turns out that $M = -1$.
$A \equiv 7 \mod 4$ is not entirely useless however.
But solving $\mod 3$ can only give you at best a solution $\mod 3$.  That's not good enough.
