Question: Find integers $q$ and $r$ such that $m = qd + r$, $0$ $\leq$ $r$ $<$ $d$.
Given: $m = -2$, $d = 5$.
This is what I have so far:
$-2 = 5q +r$
Dividing $2$ into $5$ gives $q = 2$ and $ r = 1$
So, then
$-2 = 5(2) + 1$
Because $-m$ is positive, we can write $-m = dq + r$:
$2 = 5(-2) + 1$
But since $r$ $\neq$ $0$, $m = d(-q) -r = d(-q) - r + d - d = d(-q-1) + (d-r)$
So, after plugging in, we have
$2 = 5(-3) +4$
Obviously, the left hand side of the equation does not equal the right hand side. I cannot seem to figure out what I am not doing right.
Let's redo it. You have to write $-2=5q+r$, with $0\le r<5$.
Change $-2$ into $2$: you have $2=5\cdot0+2$ (certainly not $2=5\cdot 2+1$: you have to divide $5$ into $2$, not $2$ into $5$). So $$ -2=0d-2=5\cdot0-2=5\cdot 0-5+5-2=5\cdot(-1)+3 $$
In general, if you have $m<0$ and $d>0$, you can do $$ -m=dq+r $$ and so $$ m=d(-q)-r $$ You're done if $r=0$; otherwise $0<r<d$ and you can do $$ m=d(-q)-d+d-r=d(-q-1)+d-r $$ and $0<d-r<d$, so you're done as well.