How to determine the smallest natural number solution

571 Views Asked by At
y = a + bx where a and b are rational numbers. 

I'm writing a program that uses equations which are of the same format as the equation above and I would like to find the most efficient way to get y and x.

A requirement for the solution is that both x and y are natural numbers.

2

There are 2 best solutions below

2
On BEST ANSWER

I would start by multiplying by a natural number so as to clear the denominators of $a$ and $b$. Then you can use results on linear diophantine equations to solve the resulting equation (if any natural number solutions exist).

See for example https://brilliant.org/wiki/linear-diophantine-equations-one-equation/

0
On

HINT.- Let $a=\dfrac{n_1}{d_1}$ and $b=\dfrac{n_2}{d_2}$ be both irreductible rationals.

It is necessary that $d_1$ divides $d_2$ in order to exist solutions. In fact $$y=\dfrac{n_1}{d_1}+\dfrac{n_2}{d_2}x\iff d_1d_2y=d_2n_1+d_1n_2x\Rightarrow d_1|d_2n_1$$ Since $(n_1,d_1)=1$ one has $d_1|d_2$.

What follows?