An algorithm to solve an equation with modulo?

46 Views Asked by At

given

$(2n + 1) \mod k = n \mod k $

where $k$ is known

what's an algorithm to find $n$ ?

1

There are 1 best solutions below

0
On BEST ANSWER

$2n +1 \equiv n \pmod k$ (you don't have to write $\mod k$ after every clause.

$(2n+1)-n \equiv n-n \pmod k$

$n +1 \equiv 0 \pmod k$

$n \equiv -1 \pmod k$.

So $-1 + mk$ for every integer is a solutions. $n=-1$ is a solution. $n = k -1$ is a solution $n = 3k -1$ is a solution.

All this solutions as a group $\{......, -k-1, -1, k-1, 2k-1, 3k-1,....\}$ are consider the solution. We say this is the equivalence class of $-1$ and all those numbers are basically considered to be the same thing.

=====

Okay..... less abstract and more basic.

$2n+1 \mod k = n \mod k$ means that there is some integer $m$ where

$2n + 1 = n + m\times k$.

So $n = -1 + m\times k$. Now any $m$ will yield a solution.

$n = -1 + m\times k$ for any integer $m$.