TITLE: An effcient method of solving a Diophantine equation with 3 variables $Ax+By+Cz=D$?
QUESTION [2 upvotes]: I'm trying to make an efficient algorithm to find one of the solutions and how many solutions there are to the equation $$Ax+By+Cz=D$$ where $A,B,C,D\in \mathbb Z$ and the range for $x,y,z\in \mathbb Z$ are given by the user.
I saw this: https://math.stackexchange.com/a/20944/146115 answer but when I tried to apply it, it was wrong. 
For example: $2x-3y-z=5$ in range $[-2,2]$ I know that it has 6 solutions but when I use the method in the above solution (2) I get: $\gcd (2,3)=1 \to w-z=5$ but this equation has no solutions in $[-2,2]$.
Is there another method to make this problem easier to solve, i.e, is there an efficient algorithm that will run on less than $O(n^3)$ runtime?

REPLY [2 votes]: If you calculate $z=\frac{D-Ax-By}{C}$ for all $x,y$ and then check if $z$ is an integer and in your range it will take $O(n^2)$.
And with the $\gcd$ method you won't gain anything on that.
{"set_name": "stack_exchange", "score": 2, "question_id": 1032593}