I have this problem:
$\frac{a}{5} + \frac{b}{8} = \frac{31}{40}$
I now the answer is $a=2$ and $b=3$.
I tried doing a table with simple formula:
$(a*8) + (b*5)= 31$
So, I do the table:
\begin{array}{c|cccc} a\backslash b& 1& 2& 3& 4& 5& 6& 7 \\ \hline 1& 13& 18& 23& 28& 33& 38& 43 \\ 2& 21& 26& \color{green}{\mathbf{31}}& 36& 41& 46& 51 \\ 3& 29& 34& 39& 44& 49& 54& 59 \\ 4& 37& 42& 47& 52& 57& 62& 67 \\ \end{array}
But I think maybe have another method without brute force.
How I can solve this problem with the best way?
If you assume that $a,b$ are positive integers (as it seems you do), then you can write $$5b=31-8a.$$
That means $31-8a$ has to be $\geq 0$, or $a\leq 3$. So you are just left to try $a=1,2,3$. Only $a=2$ gives an integer value of $b$.