If I have these equations
$a\equiv b \pmod c$
$d\equiv e \pmod c$
All known except $c$
and $\gcd(b−a,e−d)=1$
how do I find the unique solution for $c$?
and if the gcd!= 1 how do I find some possible solutions?
If I have these equations
$a\equiv b \pmod c$
$d\equiv e \pmod c$
All known except $c$
and $\gcd(b−a,e−d)=1$
how do I find the unique solution for $c$?
and if the gcd!= 1 how do I find some possible solutions?
$\begin{eqnarray}{\bf Hint}\qquad\quad a\equiv b\!\!\pmod{\! c}\\d\equiv e\!\!\pmod{\! c}\end{eqnarray}\iff $ $\begin{eqnarray} c\mid a-b\\c\mid d-e\end{eqnarray}\iff c\mid\gcd(a-b,d-e)$
This first equivalence is by definition of congruence, and the second is the universal gcd property.
In both cases, $c$ can be any of the (not necessarily prime) divisors of the $gcd$.
So you can simply pick $c=gcd(b-a,e-d)$.
for (int c=gcd; c>0; c--)until you find a $c$ for which $a \equiv b \pmod c$ and $d \equiv e \pmod c$. – barak manos May 11 '14 at 14:57