How would one solve a linear equation in two integer variables? For example, how would I find integers $a$ and $b$ that satisfy the following equation?
$$5a - 12b = 13$$
I always resorted to trial and error when doing something like this and more often than not I would finally reach my answer. But for this one I just kept going and going to no avail. So it finally brought about the concern that trial and error wasn't always going to work.
So what would be the best way to get two integer solutions to the above equation?

The method here is to repeatedly putting new variables:
$5a-12b=13 \Leftrightarrow 5a=12b+13 \Leftrightarrow a=\frac{12b+13}{5}=2b+2+\frac{2b+3}{5}$
Put $\frac{2b+3}{5}=c$ with $c$ is an integer (because $a$ or $2b+2+c$ is an integer)
$\Leftrightarrow 2b+3=5c \Leftrightarrow 2b-5c=-3$ or $b=\frac{5c-3}{2}$.
$b$ is an integer $\Leftrightarrow 5c-3$ is divisible by $2 \Leftrightarrow c$ is an odd number.
Put $c=2k+1$ ($k$ is an integer), we have $b= \frac{5c-3}{2}=\frac{5(2k+1)-3}{2}=5k+1.$
$\Rightarrow a=\frac{12b+13}{5}=\frac{12(5k+1)+13}{5}=12k+5$.
The equation has infinite solutions: $\begin{cases}a=12k+5\\b=5k+1\end{cases}$, $\forall k\in \mathbb{Z}$.
Trial-and-error can still be applied for any numbers multiplied by $a$, $b$, as long as their $GCD$ is $1$.
For example this ugly equation: $73a+89b=3$. You won't have time to do trial-and-error, so here's a way to make it smaller:


*

*Put $a=\frac{3-89b}{73}=\frac{3-16b}{73}-b$, then $\frac{3-16b}{73} \in \mathbb{Z}$ because $a,b\in \mathbb{Z}$.

*Put $c=\frac{3-16b}{73}$, then $3-16b=73c$ or $b=\frac{3-73c}{16}=\frac{3-9c}{16}-4c$, then $\frac{3-9c}{16} \in \mathbb{Z}$ because $b,c\in \mathbb{Z}$.

*Put $d=\frac{3-9c}{16}$, then $3-9c=16d$ or $c=\frac{3-16d}{9}=\frac{3-7d}{9}-d$, then $\frac{3-7d}{9} \in \mathbb{Z}$ because $c,d\in \mathbb{Z}$.

*Put $e=\frac{3-7d}{9}$, then $3-7d=9e$ or $d=\frac{3-9e}{7}=\frac{3-2e}{7}-e$, then $\frac{3-2e}{7} \in \mathbb{Z}$ because $d,e\in \mathbb{Z}$.

*Put $f=\frac{3-2e}{7}$, then $3-2e=7f$ or $e=\frac{3-7f}{2}=\frac{1-f}{2}+1-3f$, then $\frac{1-f}{2} \in \mathbb{Z}$ because $e,f\in \mathbb{Z}$.
$e$ would be an integer if and only if $f=2k+1$ or $f$ odd
$\Rightarrow e=-7k-2$
$\Rightarrow d=9k+3$
$\Rightarrow c=-16k-5$
$\Rightarrow {\begin{cases}a=-89k-28\\b=73k+23\end{cases}}$
