Checking a result obtained by Chinese Remainder Theorem

I have the following two linear congruences:

$$x \equiv 3 + n\mod p_1$$ $$x \equiv 3 - n\mod p_2$$

where $$p_1$$ and $$p_2$$ are distinct primes, and $$n$$ is the difference between those primes.

Does it follow that: $$x \equiv -2n \mod p_1p_2$$

My Derivation

$$x = p_1.j + 3 + n$$

$$p_1.j + 3 + n \equiv 3 - n \mod p_2$$

$$p_1.j \equiv - 2n \mod p_2$$

$$j \equiv -\frac{2n}{p_1} \mod p_2$$

$$j = p_2.k -\frac{2n}{p_1}$$

$$x = p_1(p_2.k -\frac{2n}{p_1})$$

$$x = p_1p_2k-2n$$

$$x \equiv -2n \mod p_1p_2$$

Is the derivation okay?

The only expression I'm not 100% sure about is $$j \equiv -\frac{2n}{p_1} \mod p_2$$ because $$\frac{2n}{p_1}$$ wouldn't be an integer under normal division and I've forgotten how modular division works.

• $a \equiv \frac n2 \pmod p$ does not mean $a = pk + \frac n2$. If means $a = pk + m$ where $2m \equiv n\pmod p$ so $2m = n+jp$. Oct 1, 2019 at 19:10

You made a few basic mistakes. First, note you have

$$x = p_1.j + 3 + n \tag{1}\label{eq1A}$$

From

$$j = p_2.k -\frac{2n}{p_1} \tag{2}\label{eq2A}$$

you then state that

$$x = p_1(p_2.k -\frac{2n}{p_1}) \tag{3}\label{eq3A}$$

You just replaced $$j$$ in the first equation, but forgot account for the $$3 + n$$ terms. When you include those, you would then get

$$x = p_1 p_2 k - n + 3 \tag{4}\label{eq4A}$$

A second mistake is that, as you mention, you are dividing $$2n$$ by $$p_1$$. You can do this, but then $$k$$ will not be an integer if $$\frac{2n}{p_1}$$ is not an integer. Thus, when you are no longer dealing with integers, any result would not necessarily be valid if you then tried to apply it to integers, as you do at the end with your modulo result of

$$x \equiv -2n \mod p_1p_2 \tag{5}\label{eq5A}$$

since, even when adjusting $$-2n$$ to be $$3 - n$$, it's only true if $$k$$ is an integer.

$$p_1.j \equiv - 2n \mod p_2 \tag{6}\label{eq6A}$$

you can just say something like

$$p_1 j = p_2 k - 2n \mod p_2 \tag{7}\label{eq7A}$$

Substituting this back into \eqref{eq1A} just gives

$$x = p_2 k - 2n + 3 - n = p_2 k - n + 3 \tag{8}\label{eq8A}$$

which is just a restatement of your second modulo equation of $$x \equiv 3 - n\mod p_2$$.

To solve the $$2$$ modulo equations to determine $$x$$ for some given $$n, p_1$$ and $$p_2$$, you can use the Chinese Remainder Theorem (e.g., as described in How can I solve a problem using the Chinese remainder theorem and how does mod operator is understood correctly? for $$3$$ equivalent modulo equations).

• As $n = |p_1 - p_2|$ would it be valid to square both sides of your equation $(6)$, substitute it in and expand, then remove terms including $p_2$ to get $j^2 = 4$ mod $p_2$? Oct 1, 2019 at 18:34
• If I understand you correctly, you're saying that you have a specific value for $n$, i.e., $n = |p_1 - p_2|$. If so, then you can square both side of my equation (6) to get $p_1^2 j^2 \equiv 4(p_1^2 - 2p_1p_2 + p_2^2) \pmod{p_2}$ which, as you say, allows you to state that $j^2 \equiv 4 \pmod{p_2}$. Oct 1, 2019 at 18:40
• Yeah, I mentioned it in the question, but I never used that fact in my faulty derivation. Thank you Oct 1, 2019 at 18:43
• @BradGraham Yes, I see it now. I missed that aspect of $n$ initially when I read the question. Oct 1, 2019 at 18:57