0

I am trying to teach myself modular arithmetic to solve a programming challenge. Basically it needs to solve this kind of system of modular equation,

\begin{align*} 2444 = 960x \pmod{2618} \end{align*}

except the number is very large.

I know the basic concept of modulo but that is it, I don't even know the term to search on google to help solve me this.

How do you solve for $x$?

Blue
  • 75,673
  • 1
    Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Aug 31 '21 at 16:36
  • You can search for "solving linear congruences"; there is definitely an algorithm, which is very similar to the algorithm for calculating greatest common divisors. – Greg Martin Aug 31 '21 at 16:53
  • 1
    You essentially want to find solutions to the equation $960x + 2618y = 2444$. Here is how to do that. – Arturo Magidin Aug 31 '21 at 20:59
  • While you may be interested in a "programming challenge", the programming tag is, quote, "For mathematical questions related to programming, and questions where a computer-aided solution is strongly suggested. A strong connection with a mathematical topic is needed to make programming questions on-topic." That is not what this equation is about. – Arturo Magidin Aug 31 '21 at 21:01
  • 1
    The Extended Euclidean Algorithm is useful in solving these sort of equations. There are many implementations on the web and on this site. The one I use is given in this answer. – robjohn Aug 31 '21 at 21:12

1 Answers1

2
  1. Since for each $n\in\mathbb N$ and $a,b,c\in\mathbb Z,$ $$ac\equiv bc \pmod{n}\iff a\equiv b \pmod{\frac n{\gcd\left(c,n\right)}},$$ we have $$960x \equiv 2444 \pmod{2618} \\\iff 240x \equiv 611 \pmod{1309}.$$

  2. The previous line is equivalent to the system $$\begin{align*} 240x&\equiv 611 \pmod{7}\\240x&\equiv 611 \pmod{11}\\240x&\equiv611 \pmod{17}.\end{align*}$$

  3. Solving it is equivalent to obtaining the $x$-solution of the Diophantine equation (a polynomial of which only integer solutions are of interest) $$240x+1309y=611.$$

  4. Noting that $\gcd(240,1309)=1,$ i.e., $240$ has a multiplicative inverse; continuing from Point $1\dots.$

    Euclidean algorithm: $$\begin{align*} 1309&=5(240)+109\\240&=2(109)+22\\109&=4(22)+21\\22&=1(21)+1 \end{align*}$$ Reversing the above equations: $$\begin{align*} 1&=22-1(21)\\&=22-(109-4(22))\\&=5(22)-109\\&=5(240-2(109))-109\\&=5(240)-11(109)\\&=5(240)-11(1309-5(240))\\&=60(240)-11(1309)\end{align*}$$ In $\mathbb Z_{1309}$, $$\begin{align*} 1&=60(240)\\240^{-1}&=60.\end{align*}$$ Therefore $$960x \equiv 2444 \pmod{2618} \\\begin{array}{rcl} \qquad\qquad\iff x&\equiv& 60\times 611\\ &\equiv&8\pmod{1309}.\end{array}$$

Arturo Magidin
  • 398,050
ryang
  • 38,879
  • 14
  • 81
  • 179
  • Nice solution. Does step 2 have any relevance to the rest of the solution. I can't seem to find where you use the knowledge obtained in that step. – Alan Abraham Aug 31 '21 at 21:52
  • @AlanAbraham It appears to derive from the Chinese remainder theorem. https://en.wikipedia.org/wiki/Chinese_remainder_theorem – egglog Aug 31 '21 at 22:00
  • @egglog Yes, I can see that. I'm just not seeing where it is implemented into the rest of the solution. – Alan Abraham Sep 01 '21 at 04:29
  • @AlanAbraham I should've been clearer that 2 & 3 are extra-informational points and alternative solution paths. For example, we might continue from Point 3 using continued fractions. I think the extended Euclidean algorithm is the most straightforward. – ryang Sep 01 '21 at 05:15