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

  • Context: MHB 
  • Thread starter Thread starter shamieh
  • Start date Start date
Click For Summary
SUMMARY

The discussion focuses on calculating the quotient and remainder for negative integers using the modulus operation. Specifically, for the values $a = -111$ and $m = 99$, the correct calculations yield $a \mod m = 87$ and $a \div m = -2$. In the case of $a = -9999$ and $m = 101$, the correct results are $a \mod m = 0$ and $a \div m = -99$. The key takeaway is that the remainder must always fall within the range of $0$ to $m - 1$ for positive $m$, and the method involves rounding down the division result to determine the quotient.

PREREQUISITES
  • Understanding of modulus operation and its properties
  • Familiarity with integer division and rounding techniques
  • Basic knowledge of negative numbers in arithmetic
  • Concept of quotient and remainder in division
NEXT STEPS
  • Learn about integer division and modulus in programming languages like Python or Java
  • Explore the mathematical properties of negative numbers in modular arithmetic
  • Study the floor function and its applications in rounding
  • Investigate common pitfalls in modulus calculations with negative integers
USEFUL FOR

Mathematicians, computer scientists, students learning modular arithmetic, and anyone interested in understanding division and remainder operations with negative numbers.

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$
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 29 ·
Replies
29
Views
4K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · 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
4K
  • · Replies 1 ·
Replies
1
Views
2K