How to solve equation of the form: $A*i*j + B*i +C*j=N$

50 Views Asked by At

I have an equation of the form $A*i*j + B*i +C*j = N$ where I have the values of $A,B,C$ and $N$ and I want to solve for integer values of $i$ and $j$.

How would I approach this? I could try trial and error but the numbers I'm working with are relatively large (eg $>10^{40}$). But I'm also happy to work on understanding the process with much smaller numbers. I'm not sure if it matters, but it's also possible there will not be a solution.

2

There are 2 best solutions below

1
On BEST ANSWER

Multiply the whole equation by $A$.

\begin{align} A^2ij+ABi+ACj&=AN\\ (Ai+C)(Aj+B)&=AN+BC \end{align}

So $Ai+C$ and $Aj+B$ are factors of $AN+BC$.

For example, consider $2ij+3i+7j=336$. the equation can be written as

\begin{align} 2ij+3i+7j&=336\\ 4ij+6i+14j&=672\\ (2i+7)(2j+3)&=693 \end{align}

$693=3^2\cdot7\cdot11$.

Factors of $693$ has the form $\pm3^a\cdot 7^b\cdot 11^c$, where $a\in\{0,1,2\}$ and $b,c\in\{0,1\}$. The numner of possible factors is $2\times3\times2\times2=24$.

S0, all possible $2i+7$ are $\pm1$, $\pm 3$, $\pm9$, $\pm7$, $\pm 21$, $\pm63$, $\pm 11$, $\pm 33$, $\pm 99$, $\pm77$, $\pm231$ and $\pm693$.

All possible $(i,j)$ are $(-3,345)$, $(-2,114)$, $(1,37)$, $(0,48)$, $(7,15)$, $(28,4)$, $(2,30)$, $(13,9)$, $(46,2)$, $(35,3)$, $(112,0)$, $(343,-1)$, $(-4,-348)$, $(-5,-117)$, $(-8,-40)$, $(-7,-51)$, $(-14,-18)$, $(-35,-7)$, $(-9,-33)$, $(-20,-12)$, $(-53,-5)$, $(-42,-6)$, $(-119,-3)$, $(-350,-2)$ .

2
On

Here's an idea, not a fully formed approach.

You wish to solve $$ Aij+Bi+Cj=N. $$

If we complete the square on the LHS, we get $$ A\left(i+\frac{C}{A}\right)\left(j+\frac{B}{A}\right)-\frac{BC}{A}=N. $$

Multiplying through by $A$, we get $$ (Ai+C)(Aj+B)=AN+BC. $$

Therefore, both $(Ai+C)$ and $(Aj+B)$ must be factors of $AN+BC$. If it is possible to write out all the factors of $AN+BC$, then for factors $x_1x_2=AN+BC$, you have $i=\frac{x_1-C}{A}$ and $j=\frac{x_2-B}{A}$, all you need to do is to check that these are integers or not.