This is a spot where being a teacher gives you a little tunnel vision. While it is mathematical, it’s very relevant to coding! Easiest way to ensure integer answers is by defining the answers and calculating constants. So, for Ax+By=C, where A, B and C are integers, define A, B, x, and y, and calculate C.
Edit: (Additional clarification) Define A_1, B_1, A_2, B_2, x and y. Then, calculate C_1 and C_2.