<?xml version="1.0" encoding="UTF-8" standalone="yes"?><oembed><version><![CDATA[1.0]]></version><provider_name><![CDATA[Chaos at the Sky]]></provider_name><provider_url><![CDATA[https://chaosatthesky.wordpress.com]]></provider_url><author_name><![CDATA[chaotic_iak]]></author_name><author_url><![CDATA[https://chaosatthesky.wordpress.com/author/chaoticiak/]]></author_url><title><![CDATA[A/B + C/D]]></title><type><![CDATA[link]]></type><html><![CDATA[<p>I was contacted by a friend that maintains an online judge, asking about the solution to a particular problem that has existed for how many days on an &#8220;easy&#8221; section.</p>
<p>Basically, the problem is this: given positive integers A, B, C, D, compute A/B + C/D and simplify it. You are guaranteed that if you represent A/B + C/D = E/F in lowest terms, then all of A,B,C,D,E,F fit in p-bit integers (in the problem, p = 64). Your task is to find this E and F.</p>
<p><!--more--></p>
<p>How do you approach this problem? If you have an integer type that can support more than p bits (say, p = 32 and <code>long long</code> on C++ that can fit 64 bits, or just use Java&#8217;s <code>BigInteger</code> or Python&#8217;s built-in integer type), this is pretty easy. Otherwise, you might also try making BigInteger-like type; say, making a class containing two p-bit integers and implementing arithmetical operations with it.</p>
<p>I also found a solution that doesn&#8217;t involve those, but it&#8217;s terribly, terribly messy&#8230;</p>
<p>First, simplify <img src="https://s0.wp.com/latex.php?latex=%5Cfrac%7BA%7D%7BB%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=%5Cfrac%7BA%7D%7BB%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=%5Cfrac%7BA%7D%7BB%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="&#92;frac{A}{B}" class="latex" /> and <img src="https://s0.wp.com/latex.php?latex=%5Cfrac%7BC%7D%7BD%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=%5Cfrac%7BC%7D%7BD%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=%5Cfrac%7BC%7D%7BD%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="&#92;frac{C}{D}" class="latex" />; call the results <img src="https://s0.wp.com/latex.php?latex=%5Cfrac%7Ba%7D%7Bb%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=%5Cfrac%7Ba%7D%7Bb%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=%5Cfrac%7Ba%7D%7Bb%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="&#92;frac{a}{b}" class="latex" /> and <img src="https://s0.wp.com/latex.php?latex=%5Cfrac%7Bc%7D%7Bd%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=%5Cfrac%7Bc%7D%7Bd%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=%5Cfrac%7Bc%7D%7Bd%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="&#92;frac{c}{d}" class="latex" />, where <img src="https://s0.wp.com/latex.php?latex=a&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=a&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=a&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="a" class="latex" /> and <img src="https://s0.wp.com/latex.php?latex=b&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=b&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=b&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="b" class="latex" /> are coprime, and so as <img src="https://s0.wp.com/latex.php?latex=c&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=c&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=c&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="c" class="latex" /> and <img src="https://s0.wp.com/latex.php?latex=d&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=d&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=d&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="d" class="latex" />.</p>
<p>Now, let <img src="https://s0.wp.com/latex.php?latex=b+%3D+kx&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=b+%3D+kx&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=b+%3D+kx&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="b = kx" class="latex" />, <img src="https://s0.wp.com/latex.php?latex=d+%3D+ky&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=d+%3D+ky&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=d+%3D+ky&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="d = ky" class="latex" />, where <img src="https://s0.wp.com/latex.php?latex=x&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=x&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=x&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="x" class="latex" /> and <img src="https://s0.wp.com/latex.php?latex=y&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=y&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=y&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="y" class="latex" /> are coprime; this means <img src="https://s0.wp.com/latex.php?latex=k&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=k&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=k&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="k" class="latex" /> is their GCD. Thus our sought value is <img src="https://s0.wp.com/latex.php?latex=%5Cfrac%7Ba%7D%7Bkx%7D+%2B+%5Cfrac%7Bc%7D%7Bky%7D+%3D+%5Cfrac%7Bay%2Bcx%7D%7Bkxy%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=%5Cfrac%7Ba%7D%7Bkx%7D+%2B+%5Cfrac%7Bc%7D%7Bky%7D+%3D+%5Cfrac%7Bay%2Bcx%7D%7Bkxy%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=%5Cfrac%7Ba%7D%7Bkx%7D+%2B+%5Cfrac%7Bc%7D%7Bky%7D+%3D+%5Cfrac%7Bay%2Bcx%7D%7Bkxy%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="&#92;frac{a}{kx} + &#92;frac{c}{ky} = &#92;frac{ay+cx}{kxy}" class="latex" />. Since each of <img src="https://s0.wp.com/latex.php?latex=%28a%2Cx%29%2C+%28c%2Cy%29%2C+%28x%2Cy%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=%28a%2Cx%29%2C+%28c%2Cy%29%2C+%28x%2Cy%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=%28a%2Cx%29%2C+%28c%2Cy%29%2C+%28x%2Cy%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="(a,x), (c,y), (x,y)" class="latex" /> are coprime, <img src="https://s0.wp.com/latex.php?latex=ay%2Bcx&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=ay%2Bcx&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=ay%2Bcx&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="ay+cx" class="latex" /> and <img src="https://s0.wp.com/latex.php?latex=xy&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=xy&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=xy&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="xy" class="latex" /> will be coprime. (Suppose they don&#8217;t, and suppose they share a common prime factor <img src="https://s0.wp.com/latex.php?latex=p&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=p&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=p&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="p" class="latex" /> that divides <img src="https://s0.wp.com/latex.php?latex=x&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=x&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=x&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="x" class="latex" />. Clearly <img src="https://s0.wp.com/latex.php?latex=cx&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=cx&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=cx&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="cx" class="latex" /> is divisible by <img src="https://s0.wp.com/latex.php?latex=p&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=p&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=p&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="p" class="latex" />, so to make <img src="https://s0.wp.com/latex.php?latex=ay%2Bcx&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=ay%2Bcx&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=ay%2Bcx&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="ay+cx" class="latex" /> divisible by <img src="https://s0.wp.com/latex.php?latex=p&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=p&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=p&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="p" class="latex" />, we need <img src="https://s0.wp.com/latex.php?latex=ay&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=ay&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=ay&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="ay" class="latex" /> divisible by <img src="https://s0.wp.com/latex.php?latex=p&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=p&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=p&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="p" class="latex" />. But since <img src="https://s0.wp.com/latex.php?latex=p&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=p&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=p&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="p" class="latex" /> is a factor of <img src="https://s0.wp.com/latex.php?latex=x&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=x&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=x&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="x" class="latex" />, and <img src="https://s0.wp.com/latex.php?latex=a&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=a&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=a&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="a" class="latex" /> and <img src="https://s0.wp.com/latex.php?latex=y&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=y&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=y&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="y" class="latex" /> are both coprime to <img src="https://s0.wp.com/latex.php?latex=x&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=x&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=x&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="x" class="latex" />, both <img src="https://s0.wp.com/latex.php?latex=a&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=a&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=a&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="a" class="latex" /> and <img src="https://s0.wp.com/latex.php?latex=y&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=y&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=y&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="y" class="latex" /> cannot have <img src="https://s0.wp.com/latex.php?latex=p&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=p&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=p&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="p" class="latex" /> as a factor, contradiction.)</p>
<p>Thus, if <img src="https://s0.wp.com/latex.php?latex=ay%2Bcx&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=ay%2Bcx&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=ay%2Bcx&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="ay+cx" class="latex" /> is also coprime with <img src="https://s0.wp.com/latex.php?latex=k&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=k&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=k&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="k" class="latex" />, we&#8217;re done; we have <img src="https://s0.wp.com/latex.php?latex=E+%3D+ay%2Bcx&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=E+%3D+ay%2Bcx&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=E+%3D+ay%2Bcx&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="E = ay+cx" class="latex" /> and <img src="https://s0.wp.com/latex.php?latex=F+%3D+kxy&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=F+%3D+kxy&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=F+%3D+kxy&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="F = kxy" class="latex" />, and both fit inside our limit. The problem is when <img src="https://s0.wp.com/latex.php?latex=ay%2Bcx&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=ay%2Bcx&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=ay%2Bcx&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="ay+cx" class="latex" /> is not coprime with <img src="https://s0.wp.com/latex.php?latex=k&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=k&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=k&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="k" class="latex" />, and consequently <img src="https://s0.wp.com/latex.php?latex=ay%2Bcx%2C+kxy&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=ay%2Bcx%2C+kxy&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=ay%2Bcx%2C+kxy&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="ay+cx, kxy" class="latex" /> are not necessarily within our limit.</p>
<p>Here&#8217;s the magic. <img src="https://s0.wp.com/latex.php?latex=a&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=a&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=a&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="a" class="latex" /> is within limit, and if we take <img src="https://s0.wp.com/latex.php?latex=a%27+%5Cequiv+a+%5Cpmod+k&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=a%27+%5Cequiv+a+%5Cpmod+k&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=a%27+%5Cequiv+a+%5Cpmod+k&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="a&#039; &#92;equiv a &#92;pmod k" class="latex" /> such that <img src="https://s0.wp.com/latex.php?latex=a%27+%5Cin+%5B-%5Cfrac%7Bk%7D%7B2%7D%2C+%5Cfrac%7Bk%7D%7B2%7D%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=a%27+%5Cin+%5B-%5Cfrac%7Bk%7D%7B2%7D%2C+%5Cfrac%7Bk%7D%7B2%7D%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=a%27+%5Cin+%5B-%5Cfrac%7Bk%7D%7B2%7D%2C+%5Cfrac%7Bk%7D%7B2%7D%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="a&#039; &#92;in [-&#92;frac{k}{2}, &#92;frac{k}{2})" class="latex" />, we have <img src="https://s0.wp.com/latex.php?latex=%7Ca%27%7C+%5Cle+%5Cfrac%7Bk%7D%7B2%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=%7Ca%27%7C+%5Cle+%5Cfrac%7Bk%7D%7B2%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=%7Ca%27%7C+%5Cle+%5Cfrac%7Bk%7D%7B2%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="|a&#039;| &#92;le &#92;frac{k}{2}" class="latex" />. Also, <img src="https://s0.wp.com/latex.php?latex=ky+%3D+d&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=ky+%3D+d&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=ky+%3D+d&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="ky = d" class="latex" /> fits within <img src="https://s0.wp.com/latex.php?latex=p&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=p&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=p&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="p" class="latex" />-bit integer, so <img src="https://s0.wp.com/latex.php?latex=a%27y+%5Cle+%5Cfrac%7Bky%7D%7B2%7D+%3D+%5Cfrac%7Bd%7D%7B2%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=a%27y+%5Cle+%5Cfrac%7Bky%7D%7B2%7D+%3D+%5Cfrac%7Bd%7D%7B2%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=a%27y+%5Cle+%5Cfrac%7Bky%7D%7B2%7D+%3D+%5Cfrac%7Bd%7D%7B2%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="a&#039;y &#92;le &#92;frac{ky}{2} = &#92;frac{d}{2}" class="latex" /> must fit within <img src="https://s0.wp.com/latex.php?latex=%28p-1%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=%28p-1%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=%28p-1%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="(p-1)" class="latex" />-bit integer! We do the same with <img src="https://s0.wp.com/latex.php?latex=c&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=c&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=c&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="c" class="latex" />, getting <img src="https://s0.wp.com/latex.php?latex=c%27&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=c%27&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=c%27&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="c&#039;" class="latex" />. Additionally, the sum of two <img src="https://s0.wp.com/latex.php?latex=%28p-1%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=%28p-1%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=%28p-1%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="(p-1)" class="latex" />-bit integers fits within <img src="https://s0.wp.com/latex.php?latex=p&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=p&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=p&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="p" class="latex" />-bit integer! This allows us to obtain a number <img src="https://s0.wp.com/latex.php?latex=a%27y%2Bc%27x+%5Cequiv+ay%2Bcx+%5Cpmod+k&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=a%27y%2Bc%27x+%5Cequiv+ay%2Bcx+%5Cpmod+k&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=a%27y%2Bc%27x+%5Cequiv+ay%2Bcx+%5Cpmod+k&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="a&#039;y+c&#039;x &#92;equiv ay+cx &#92;pmod k" class="latex" /> which fits within our limit.</p>
<p>Next, suppose that <img src="https://s0.wp.com/latex.php?latex=%5Cgcd%28ay%2Bcx%2C+k%29+%3D+g&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=%5Cgcd%28ay%2Bcx%2C+k%29+%3D+g&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=%5Cgcd%28ay%2Bcx%2C+k%29+%3D+g&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="&#92;gcd(ay+cx, k) = g" class="latex" />. Then we also have <img src="https://s0.wp.com/latex.php?latex=%5Cgcd%28a%27y%2Bc%27x%2C+k%29+%3D+g&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=%5Cgcd%28a%27y%2Bc%27x%2C+k%29+%3D+g&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=%5Cgcd%28a%27y%2Bc%27x%2C+k%29+%3D+g&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="&#92;gcd(a&#039;y+c&#039;x, k) = g" class="latex" />, because <img src="https://s0.wp.com/latex.php?latex=ay%2Bcx&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=ay%2Bcx&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=ay%2Bcx&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="ay+cx" class="latex" /> and <img src="https://s0.wp.com/latex.php?latex=a%27y%2Bc%27x&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=a%27y%2Bc%27x&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=a%27y%2Bc%27x&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="a&#039;y+c&#039;x" class="latex" /> differ by a multiple of <img src="https://s0.wp.com/latex.php?latex=k&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=k&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=k&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="k" class="latex" />. This allows us to find the value of <img src="https://s0.wp.com/latex.php?latex=g&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=g&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=g&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="g" class="latex" />. Thus, representing <img src="https://s0.wp.com/latex.php?latex=k+%3D+gk%27&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=k+%3D+gk%27&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=k+%3D+gk%27&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="k = gk&#039;" class="latex" />, we have <img src="https://s0.wp.com/latex.php?latex=F+%3D+k%27xy&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=F+%3D+k%27xy&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=F+%3D+k%27xy&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="F = k&#039;xy" class="latex" />, which by assumption fits in our limit. We also know that <img src="https://s0.wp.com/latex.php?latex=E+%3D+%5Cfrac%7Bay%2Bcx%7D%7Bg%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=E+%3D+%5Cfrac%7Bay%2Bcx%7D%7Bg%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=E+%3D+%5Cfrac%7Bay%2Bcx%7D%7Bg%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="E = &#92;frac{ay+cx}{g}" class="latex" />, and so it will be within limit, but how to divide by <img src="https://s0.wp.com/latex.php?latex=g&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=g&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=g&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="g" class="latex" />?</p>
<p>We do the same thing as above. We can compute <img src="https://s0.wp.com/latex.php?latex=a+%3D+a%27+%2B+qk+%3D+a%27+%2B+qk%27g&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=a+%3D+a%27+%2B+qk+%3D+a%27+%2B+qk%27g&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=a+%3D+a%27+%2B+qk+%3D+a%27+%2B+qk%27g&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="a = a&#039; + qk = a&#039; + qk&#039;g" class="latex" />, and thus <img src="https://s0.wp.com/latex.php?latex=ay+%3D+a%27y+%2B+qyk%27g&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=ay+%3D+a%27y+%2B+qyk%27g&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=ay+%3D+a%27y+%2B+qyk%27g&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="ay = a&#039;y + qyk&#039;g" class="latex" />. Thus we can add <img src="https://s0.wp.com/latex.php?latex=qyk%27+%3D+%5Cfrac%7B%28a-a%27%29%7D%7Bg%7D+%5Ccdot+y&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=qyk%27+%3D+%5Cfrac%7B%28a-a%27%29%7D%7Bg%7D+%5Ccdot+y&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=qyk%27+%3D+%5Cfrac%7B%28a-a%27%29%7D%7Bg%7D+%5Ccdot+y&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="qyk&#039; = &#92;frac{(a-a&#039;)}{g} &#92;cdot y" class="latex" /> into the sum, while retaining <img src="https://s0.wp.com/latex.php?latex=a%27y&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=a%27y&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=a%27y&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="a&#039;y" class="latex" /> for later. Similarly, if we let <img src="https://s0.wp.com/latex.php?latex=c+%3D+c%27+%2B+rk&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=c+%3D+c%27+%2B+rk&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=c+%3D+c%27+%2B+rk&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="c = c&#039; + rk" class="latex" />, we can add <img src="https://s0.wp.com/latex.php?latex=rxk%27+%3D+%5Cfrac%7B%28c-c%27%29%7D%7Bg%7D+%5Ccdot+x&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=rxk%27+%3D+%5Cfrac%7B%28c-c%27%29%7D%7Bg%7D+%5Ccdot+x&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=rxk%27+%3D+%5Cfrac%7B%28c-c%27%29%7D%7Bg%7D+%5Ccdot+x&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="rxk&#039; = &#92;frac{(c-c&#039;)}{g} &#92;cdot x" class="latex" /> into the sum, keeping <img src="https://s0.wp.com/latex.php?latex=c%27x&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=c%27x&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=c%27x&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="c&#039;x" class="latex" />. Finally, since now <img src="https://s0.wp.com/latex.php?latex=a%27y+%2B+c%27x&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=a%27y+%2B+c%27x&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=a%27y+%2B+c%27x&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="a&#039;y + c&#039;x" class="latex" /> fits in a single integer, we can also compute <img src="https://s0.wp.com/latex.php?latex=%5Cfrac%7Ba%27y%2Bc%27x%7D%7Bg%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=%5Cfrac%7Ba%27y%2Bc%27x%7D%7Bg%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=%5Cfrac%7Ba%27y%2Bc%27x%7D%7Bg%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="&#92;frac{a&#039;y+c&#039;x}{g}" class="latex" /> directly, adding into the sum too and thus producing the value of <img src="https://s0.wp.com/latex.php?latex=E&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=E&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=E&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="E" class="latex" />.</p>
<p>And there we are.</p>
<ol>
<li>Simplify <img src="https://s0.wp.com/latex.php?latex=%5Cfrac%7BA%7D%7BB%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=%5Cfrac%7BA%7D%7BB%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=%5Cfrac%7BA%7D%7BB%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="&#92;frac{A}{B}" class="latex" /> and <img src="https://s0.wp.com/latex.php?latex=%5Cfrac%7BC%7D%7BD%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=%5Cfrac%7BC%7D%7BD%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=%5Cfrac%7BC%7D%7BD%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="&#92;frac{C}{D}" class="latex" /> into <img src="https://s0.wp.com/latex.php?latex=%5Cfrac%7Ba%7D%7Bb%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=%5Cfrac%7Ba%7D%7Bb%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=%5Cfrac%7Ba%7D%7Bb%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="&#92;frac{a}{b}" class="latex" /> and <img src="https://s0.wp.com/latex.php?latex=%5Cfrac%7Bc%7D%7Bd%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=%5Cfrac%7Bc%7D%7Bd%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=%5Cfrac%7Bc%7D%7Bd%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="&#92;frac{c}{d}" class="latex" /> where <img src="https://s0.wp.com/latex.php?latex=a%2Cb&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=a%2Cb&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=a%2Cb&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="a,b" class="latex" /> are coprime, and <img src="https://s0.wp.com/latex.php?latex=c%2Cd&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=c%2Cd&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=c%2Cd&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="c,d" class="latex" /> are coprime. (This can be done by finding the respective GCD by Euclidean algorithm and dividing each from the GCD.)</li>
<li>Compute <img src="https://s0.wp.com/latex.php?latex=k+%3D+%5Cgcd%28b%2Cd%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=k+%3D+%5Cgcd%28b%2Cd%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=k+%3D+%5Cgcd%28b%2Cd%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="k = &#92;gcd(b,d)" class="latex" />, and compute <img src="https://s0.wp.com/latex.php?latex=x+%3D+%5Cfrac%7Bb%7D%7Bk%7D%2C+y+%3D+%5Cfrac%7Bd%7D%7Bk%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=x+%3D+%5Cfrac%7Bb%7D%7Bk%7D%2C+y+%3D+%5Cfrac%7Bd%7D%7Bk%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=x+%3D+%5Cfrac%7Bb%7D%7Bk%7D%2C+y+%3D+%5Cfrac%7Bd%7D%7Bk%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="x = &#92;frac{b}{k}, y = &#92;frac{d}{k}" class="latex" />.</li>
<li>Compute <img src="https://s0.wp.com/latex.php?latex=a%27%2C+c%27&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=a%27%2C+c%27&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=a%27%2C+c%27&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="a&#039;, c&#039;" class="latex" /> such that <img src="https://s0.wp.com/latex.php?latex=a%27+%5Cequiv+a+%5Cpmod+k%2C+c%27+%5Cequiv+c+%5Cpmod+k&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=a%27+%5Cequiv+a+%5Cpmod+k%2C+c%27+%5Cequiv+c+%5Cpmod+k&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=a%27+%5Cequiv+a+%5Cpmod+k%2C+c%27+%5Cequiv+c+%5Cpmod+k&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="a&#039; &#92;equiv a &#92;pmod k, c&#039; &#92;equiv c &#92;pmod k" class="latex" />, and <img src="https://s0.wp.com/latex.php?latex=a%27%2C+c%27+%5Cin+%5B-%5Cfrac%7Bk%7D%7B2%7D%2C+%5Cfrac%7Bk%7D%7B2%7D%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=a%27%2C+c%27+%5Cin+%5B-%5Cfrac%7Bk%7D%7B2%7D%2C+%5Cfrac%7Bk%7D%7B2%7D%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=a%27%2C+c%27+%5Cin+%5B-%5Cfrac%7Bk%7D%7B2%7D%2C+%5Cfrac%7Bk%7D%7B2%7D%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="a&#039;, c&#039; &#92;in [-&#92;frac{k}{2}, &#92;frac{k}{2})" class="latex" />. (This can be done by simply using the modulo operator, and in case the result is <img src="https://s0.wp.com/latex.php?latex=%5Cfrac%7Bk%7D%7B2%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=%5Cfrac%7Bk%7D%7B2%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=%5Cfrac%7Bk%7D%7B2%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="&#92;frac{k}{2}" class="latex" /> or greater, subtract <img src="https://s0.wp.com/latex.php?latex=k&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=k&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=k&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="k" class="latex" /> from it.</li>
<li>Compute <img src="https://s0.wp.com/latex.php?latex=g+%3D+%5Cgcd%28a%27y%2Bc%27x%2C+k%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=g+%3D+%5Cgcd%28a%27y%2Bc%27x%2C+k%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=g+%3D+%5Cgcd%28a%27y%2Bc%27x%2C+k%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="g = &#92;gcd(a&#039;y+c&#039;x, k)" class="latex" />, and compute <img src="https://s0.wp.com/latex.php?latex=k%27+%3D+%5Cfrac%7Bk%7D%7Bg%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=k%27+%3D+%5Cfrac%7Bk%7D%7Bg%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=k%27+%3D+%5Cfrac%7Bk%7D%7Bg%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="k&#039; = &#92;frac{k}{g}" class="latex" /></li>
<li>Compute <img src="https://s0.wp.com/latex.php?latex=F+%3D+k%27xy&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=F+%3D+k%27xy&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=F+%3D+k%27xy&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="F = k&#039;xy" class="latex" />.</li>
<li>Compute <img src="https://s0.wp.com/latex.php?latex=E+%3D+%5Cfrac%7Ba-a%27%7D%7Bg%7D+%5Ccdot+y+%2B+%5Cfrac%7Bc-c%27%7D%7Bg%7D+%5Ccdot+x+%2B+%5Cfrac%7Ba%27y%2Bc%27x%7D%7Bg%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=E+%3D+%5Cfrac%7Ba-a%27%7D%7Bg%7D+%5Ccdot+y+%2B+%5Cfrac%7Bc-c%27%7D%7Bg%7D+%5Ccdot+x+%2B+%5Cfrac%7Ba%27y%2Bc%27x%7D%7Bg%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=E+%3D+%5Cfrac%7Ba-a%27%7D%7Bg%7D+%5Ccdot+y+%2B+%5Cfrac%7Bc-c%27%7D%7Bg%7D+%5Ccdot+x+%2B+%5Cfrac%7Ba%27y%2Bc%27x%7D%7Bg%7D&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="E = &#92;frac{a-a&#039;}{g} &#92;cdot y + &#92;frac{c-c&#039;}{g} &#92;cdot x + &#92;frac{a&#039;y+c&#039;x}{g}" class="latex" />.</li>
</ol>
]]></html></oembed>