Solve modulus with constraints for multiple equations I'm trying write a program to solve equations from the following form:

$$ \begin{align}
a \bmod x &amp;= t_1 \\
b \bmod x &amp;= t_2 \\
\end{align} $$

where $a$, $b$, $t_1$ and $t_2$ are known values.

I have multiple equations of the same form and I'd like to solve them for $x$.
Assuming I have constraints on $t_1$ and on $t_2$ for some constant $C$:

$$ \begin{align}
0 \le t_1 \lt C \\
0 \le t_2 \lt C \\
\end{align} $$

e.g :
for $a=150$, $b=50$, $t1=2$, $t_2=1$:
$$ \begin{align}
150 \bmod x &amp;= 2 \\
50 \bmod x &amp;= 1 \\
1, 2 \lt 5 \\
\end{align} $$

What would be the most efficient way to program such a thing?
Expand the equivalences $150 \equiv 2 \pmod{x}$, $50 \equiv 1 \pmod{x}$ into $150 = 2 + k_1 x$, $50 = 1 + k_2 x$ for some integers $k_1, k_2$ and deduce that $148 = k_1 x, 49 = k_2 x$. There is no 
integer solution since $\gcd(148, 49) = 1$. But (for example; another system) if you replace $150$ with say $65$, then you have $\gcd(49, 63) = 7$. Since $x$ must be $&gt; t_1, t_2$ (or your given upper bound on $t_1, t_2$), we can set $x = 7$ (or other factors of the gcd which satisfy the aforementioned conditions). You can probably turn this into an algorithm. The dominant cost is gcd computation.