0

I am really new to modular arithmetic so I am not sure if what I am asking makes any sense. I have been given two arrays of length $n$ and $m$ respectively, Say $$array_{1} = {4,1,6,2,...x...}$$ $$array_{2} = {2,3,4,1,...x...}$$

I can cycle these arrays infinitely and I want to find the first position $i$ where $array_{1}[i]=array_{2}[i]=x$.

So I solve using this using Chinese Remainder Theorem.

Assuming position of $x$ in $array_{1}$ is $a$ , and $array_{2}$ is $b$, I have to solve, $$pos \equiv{a} \mod{n}$$ $$pos \equiv{b} \mod{m}$$

I know how to solve this if $n$ and $m$ are coprime. But if they are not , I want to transition from $\{n,m\}\to\{\frac{n}{gcd(n,m)},\frac{m}{gcd(n,m)}\}$. How do I achieve this?

prog_SAHIL
  • 2,543
  • 13
  • 27

0 Answers0