MHB Is It Possible to Find a Mod m and a Div m for Given Values of a and m?

  • Thread starter Thread starter shamieh
  • Start date Start date
Click For Summary
The discussion centers on finding the quotient and remainder (div m and mod m) for given values of a and m. The correct method involves dividing a by m, rounding down to find the quotient, and then calculating the remainder. For example, with a = -111 and m = 99, the calculations yield a div m of -2 and a mod m of 87. In the case of a = -9999 and m = 101, the division is exact, resulting in a div m of -99 and a mod m of 0. The importance of ensuring the remainder is within the correct range (0 to m-1) is emphasized for accuracy.
shamieh
Messages
538
Reaction score
0
Find a div m and a mod m when

$a = -111$, $m = 99$

so I got the first one:
$a =-2*99+87$ => amodm=87 and adivm = -2

so if I had $a=−9999$ and $m = 101$ would that mean that $a = −2∗101-9797$ ? so a mod m $= -9797$ and a div m =$ -2$ ?

or should it be $a =-1 *101 + -9898$ => amodm = $-9898$ and adivm = $-1$
 
Last edited:
Physics news on Phys.org
The remainder (mod) is always between $0$ and $m - 1$ inclusive (for positive $m$), that's how the quotient is unique.
 
Bacterius said:
The remainder (mod) is always between $0$ and $m - 1$ inclusive (for positive $m$), that's how the quotient is unique.

so the remainder mod, in this case is between $0$ and $100$ right (101-1)? This fact still doesn't answer my question though. I need to know if my method is correct or incorrect.
 
shamieh said:
so the remainder mod, in this case is between $0$ and $100$ right (101-1)? This fact still doesn't answer my question though. I need to know if my method is correct or incorrect.

Yes, and it does, your method is incorrect, for the remainder you found in the second case isn't in this interval and so is wrong.

In theory, to find the quotient and remainder for positive $m$ what you do is find the smallest nonnegative integer $r$ such that $a - r$ is a multiple of $m$ ($r$ will be the remainder) and then divide $a - r$ by $m$ to find $q$. In practice you usually want to find the quotient first by dividing $a$ by $m$ and rounding down, and then working out the remainder from that.

For instance with $a = -111$ and $m = 99$, you compute $a / m \approx -1.12$, which when rounded down gives $q= -2$, so that you have $a = qm + r$, that is, $-111 = (-2) 99 + r$, so $r = -111 - (-2)99 = 87$.

For $a = -9999$ and $m = 101$ we get $a / m = -99$ (it happens to be exact), so there's no need to round down and so $q = -99$, and we get $-9999 = (-99)101 + r$, so $r = -9999 - (-99)101 = 0$ (in fact you already knew the remainder was zero, since $101$ happened to divide $-9999$ as the division gave an integer).
 
Thank you for the help bacterius. This is going to sound like a really dumb question but you are saying that I need to round down $-1.12$ to $-2$ ... How in the world does $-1.12$ round down to $-2$ ?
 
OH! Bacterius I'm an idiot. I see what you are talking about. $\lfloor -1.12 \rfloor = -2$
 
There is a nice little variation of the problem. The host says, after you have chosen the door, that you can change your guess, but to sweeten the deal, he says you can choose the two other doors, if you wish. This proposition is a no brainer, however before you are quick enough to accept it, the host opens one of the two doors and it is empty. In this version you really want to change your pick, but at the same time ask yourself is the host impartial and does that change anything. The host...

Similar threads

Replies
29
Views
4K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 27 ·
Replies
27
Views
2K
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
9
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K