Solve equation with modulo operator

142 Views Asked by At

I have the equotation $$(x-g)\mod(2g)=0,\; x \in \Bbb N, n \in \Bbb N$$ I need a formula to calculate $g$ out of a given $x$, I tried WolframAlpha, but I only get pairs of numbers matching this equotation.
I heard of the inverse modulo operator, but I'm not sure if or how this operate could help me here. Since I'm not a mathematician you can hopefully forgive me, if this is a stupid question.
Any help is appreciated.

EDIT: Some Testcases:
for $x=[1,3,5,7,9,11],\; g=1$,
for $x=[2,6,10,14,18,22],\; g=2$,
for $x=[4,12,20,28,36,44],\; g=3$,
for $x=[8,24,40,56,72,88],\; g=4$,

2

There are 2 best solutions below

0
On BEST ANSWER

You want that $x-g=2gn$, where $n$ is some integer, which means $$ g=\frac{x}{2n+1} $$ So, take any odd divisor of $x$ and you'll find a value for $g$, two if you allow negative values for $g$.

For instance, if $x=1$, you only have the solutions $g=1$ or $g=-1$. For $x=3$ you can take $g=3/1=3$ or $g=3/3=1$ (or their negatives). For $x=6$, the possible values are $g=6/1=6$ or $g=6/3=2$ (plus $-6$ or $-2$).

If $x=2^k$, with $k>0$, only $g=1$ is possible.

The solution $g=4$ for $x=8$ is not good: inded $8-4\not\equiv0\pmod{2\cdot4}$.

4
On

Well $$x-g\equiv0 \pmod {2g} \iff x-g=(2g)k$$ for some integer $k$.

Then $$g=\dfrac{x}{2k+1}$$ will work whenever it's an integer. That happens for each odd factor of $x$.

I don't think there's a formula.

For every $x$ you can take $g=x$ - that corresponds to the odd factor $1$ of $x$.

For $x=1$ the only solution is $g=x=1$.

A more typical example: for $x=6$ you can have $g=6/1 = 6$ and $g=6/3 = 2$.