29

my question is

If $-27$ is divided by $5$, what would be the remainder?

Bill Dubuque
  • 272,048
mukesh
  • 315
  • 8
    Depends on convention. What is yours? There are at least a handful of conventions on how the quotient is rounded (which then determines the "remainder"). – Bill Dubuque Dec 31 '13 at 17:47
  • I'm late here! But for future visitors, if you're searching for the computer scientific answer, then here's also a very useful read with regards to this question that, IMHO, you shouldn't miss: integer division by Eric Lippert. – aderchox Nov 27 '23 at 22:55

6 Answers6

41

​​​​There are two conventions, depending on whether you allow the remainder to be negative.

Either you don't

$$-27 = -6 \times 5 + 3$$

or you do

$$-27 = -5 \times 5 + (-2)$$

Note that whatever convention you choose, the two possibilities for the remainder will always differ by $5$.

Pacerier
  • 3,369
Chris Taylor
  • 28,955
  • remainder can not be greater than Dividend – mukesh Dec 31 '13 at 17:51
  • It can not be +3, As reminder is remaining part after quotient when a dividing divident by divisor. In short none of us will have confusion on quotient, if you take in decimal point format its number coming before decimal point. Here in this case -27/5 = -5.4. So quotient is -5. So reminder is -2. – Neo Oct 10 '15 at 03:46
  • 4
    @neolivz4ever As I and many others said, there are multiple conventions on how the quotient is rounded. You are free to use your own convention, but that won't stop other people using a different one! – Chris Taylor Oct 10 '15 at 07:17
  • @ChrisTaylor: Well theorotically you can have infinite combinations of y = m.x + c combination. – Neo Oct 12 '15 at 11:18
  • 6
    @neolivz4ever But only two where the absolute value of the remainder is less than the divisor - sure, you can write 13 = 1 x 5 + 8 but no one thinks that is a justification for saying that 8 is the remainder after dividing 13 by 5. Look, you have one convention, and almost everyone in the world has a different convention. You can either admit that there are multiple valid conventions, or you can continue to pointlessly insist that you are right and the rest of the world is wrong. There is no interesting discussion to be had in either case. – Chris Taylor Oct 12 '15 at 12:29
  • Or you can write 13 = 3 x 5 + (-2), which is by default not the answer you are expecting. My point is that if one of divident or divisor is negative, remainder shoud be zero or negative. If both are positive or negative remainder should be 0 or positive. – Neo Oct 13 '15 at 05:42
  • @Neo Bill's answer (recently edited) has a case-by-case study of several possible conventions on that point. You're right that "13 = 3 x 5 + (-2)" would be unexpected as a "remainder" despite us using this idea all the time, e.g. 13 cookies shared between 3 people is almost 5 cookies each but we're 2 short. I think this is a terminology issue at heart: I wouldn't want to say it's "quotient of 5 with remainder -2" but I don't know what it should be called either, so I asked a question about it – Silverfish Mar 22 '23 at 12:13
18

Per the Euclidean Algorithm:

$$-27 = \underbrace{-6}_q\cdot \underbrace{5}_d + \underbrace{3}_r$$

where $q$ is the quotient when $-27$ (dividend) is divided by the divisor $d=5$, and $r$ is the remainder. It is standard to represent the remainder $r$ such that $0 \leq r \lt \;d.$

amWhy
  • 209,954
  • in this case r is 3. but it is greater than Dividend. after division remainder shoul be less than Dividend i think. – mukesh Dec 31 '13 at 17:54
  • 2
    Here, $5$ is the divisor and $r\lt 5$. $;;-27$ is the dividend: the number that the divisor $5$ is dividing. Check for yourself: google "dividend" and "divisor". – amWhy Dec 31 '13 at 17:55
  • @amWhy: Could use another UV =1 – Amzoti Jan 01 '14 at 17:59
  • 1
    @amWhy, Why is it standard to constrain the remainder to a postive number? It seems to make more intuitive sense if the remainder is -2 right? – Pacerier Sep 10 '14 at 09:50
  • "The division algorithm is defined as Euclidean division" well. I would be careful. Given two positive numbers a and n, a modulo n (often abbreviated as a mod n) is the remainder of the Euclidean division of a by n, where a is the dividend and n is the divisor. Not in the case of negative numbers. Modulo is not a division, it is wrapping cyclicly. This example −11(mod7) cannot be defined as division as in the case of two positive numbers a and n. How would you visualize it? 11 mod 7 as division is easy It is 1.571 ( rounding 7 x 0.571 = 4). In the case of -11 /7 -1.571 is -4.. and not 3. – Maciej Wakowski Mar 31 '24 at 19:34
  • Part 2. You need to look at it as a cyclical wrapping. a mod n where n signifies cycle length (12 for an hour in clock, 24 hours a day, 12 months a year, etc). And a is for iterating over the cycle how many times! In the case of -11 mod 7 you have a cycle (1,2,3,4,5,6,7) but you are counting back (due to the minus!). Your starting point is 7 then so start counting 1(6),2(5).....6(1),7(7),8(6),9(5),10(4) and finally we arrived at to zero i.e 11(3). P.S. I incremented the iterator but in this case, you should count backward from 11. – Maciej Wakowski Mar 31 '24 at 19:34
  • Part 3. -9 mod -2 = -1 therefore a=bq +r != 0≤r<|b| – Maciej Wakowski Mar 31 '24 at 19:35
7

There are various conventions for how to define the quotient and remainder for the division algorithm when extended from naturals to integers, i.e. the extension to negative integers.

The remainder is uniquely determined once one defines the quotient, and many conventions are based on a choice of which direction to round the quotient, e.g. towards $\:\!0\:\!$ or, towards the nearest integer, or towards $\:\!\pm\infty.\,$ Some programming languages provide all of the possibilities, e.g. see the floor, ceiling, round, truncate functions in Common Lisp.

A web search will turn up further discussion of such conventions in many places, e.g. on Wikipedia and D. Leijen, Division and Modulus for Computer Scientists., and R. Boute, The Euclidean Definition of the Functions div and mod, which incudes the following figures

enter image description here enter image description here

On the other hand, if we are working with congruences or modular arithmetic then we are mostly concerned with the remainders - not the quotients, so it is more useful to specify the the complete systems of residues to use (which determine the quotients if need be). For example, it is often more convenient to use a balanced (signed) residue system (e.g. $\,\pm\{0,1,2\}\bmod 5$) since it is closed under the negation reflection $\,n\to -n\,$ and this symmetry often simplifies matters, e.g. when summing the residues (analogous to Gauss's grade school trick for summing an arithmetic progression) and when taking their (shifted) product, as in Wilson's theorem.

Be sure to know the difference between $\!\bmod\!$ as a (remainder) operation vs. (congruence) relation, which is discussed at length in this answer. =

Bill Dubuque
  • 272,048
  • 1
  • Daan Leijen's paper is very interesting and I recommend following that link to anyone reading this answer in future. I feel like at my age and level of education I should really know what "division" means by now, but turns there's more to it than I expected! It didn't clear up some issues I had about terminology for "negative remainders" and rounding in different directions: I have asked a new question, although it's focused on dividing two positive integers. – Silverfish Mar 18 '23 at 21:32
1

Let $m$ be a negative integer $< 0$ and let $b$ be a positive integer $> 0$.

Proposition: There exist unique integers $q$ and $r$ satisfying the following conditions:

$q \le 0$

$0 \le -r \lt b\;$ (so $r$ is a nonpositive integer)

$m = qb + r$

The proof is left as an exercise for the interested reader.


There is nothing heretical about this. To some it might even be the more natural way to perform Euclidean Division on negative numbers. Why?

You are making great progress working with integers and are using them to measure lengths. You work with many rulers using 'tick' marks, but have to select the ruler with the required ‘Ticks per Unit Length Precision Granularity’.

You know if your unit length has 5 ticks and something is 27 ticks long, that you measure it on the ruler at (5*5 + 2) ticks, or

27 ticks / (5 ticks/Units) = $(5 + \frac{2}{5})$ Units asdf

You naturally do the same thing when measuring to the left (negative lengths).

The next day you get a bit more abstract and define the rational numbers. It turns out that your method is actually the way to represent a rational number as a mixed number. Just for fun, check out

How to Convert a Negative Mixed Number Into an Improper Fraction : Fractions 101

Now convert $-5\frac{2}{5}$ into an improper fraction.

CopyPasteIt
  • 11,366
0

Reminder is 3 because $-27=-6 \cdot 5 + 3$.

mcihak
  • 614
  • 4
  • 12
-1

suppose you have a loan of 27 i.e -27.what will the loan amount which you have to pay after dividing the loan as much as possible. after dividing the loan among 5 people each with -5 you will be still left with -2.so -2 must be the remainder.

  • The remainder is generally defined to be $\geqslant 0$. So $-27$ divided by $5$ results in entire quocient $-6$ and remainder $3$. – Ramiro Mar 13 '16 at 17:42