# -3 mod 26 calculation?

• shivajikobardan
The simplest concept of a remainder is usually defined as a non-negative integer (although not always).In the usual case, we would have:$$-3 = (-1 \times 26) + 23$$As a simple analogy, I like to think in terms of a 12 hour clock.Clocks read hours as 1,2,3,4,5,6,7,8,9,10,11,12 only.Hence -3 hours would be 9 o'clock.f

#### shivajikobardan

Summary: calculating modulo i.e remainder when -3 divided by 26

The answer seems to be (26-3)mod26=23. But I'm not sure how? Is there some rule like that? I don't quite get it.

Summary: calculating modulo i.e remainder when -3 divided by 26

The answer seems to be (26-3)mod26=23. But I'm not sure how? Is there some rule like that? I don't quite get it.
What do you think it should be?

Summary: calculating modulo i.e remainder when -3 divided by 26

The answer seems to be (26-3)mod26=23. But I'm not sure how? Is there some rule like that? I don't quite get it.

Related question: What's the integer part of -3/26? Is it $$\left\lfloor - \frac{3}{26} \right\rfloor = -1\qquad\mbox{or}\qquad-\left\lfloor \frac{3}{26} \right\rfloor = 0?$$ If you use the first definition, then the remainder is $$R(x) = x - 26\left\lfloor \frac{x}{26}\right\rfloor$$ and you would have $$R(-3) = -3 - 26(-1) = 23.$$ Alternatively if you use the second approach then $$R(x) = x - 26\operatorname{sgn}(x)\left\lfloor \frac{|x|}{26}\right\rfloor$$ and you would get $R(-3) = -3$.

topsquark
What do you think it should be?
I think it should be -3 itself. As it's not divisble by 26. Just like if it was 3%26, it'd be 3.

Summary: calculating modulo i.e remainder when -3 divided by 26

The answer seems to be (26-3)mod26=23. But I'm not sure how? Is there some rule like that? I don't quite get it.
##a \equiv b ## (mod ## n ##) means that ##(a-b)## is an integer multiple of ##n## i.e. ##a-b = kn## for some integer ##k##. You can also phrase this as a and b have same remainer when dividing with n: a = pn + ra and b = qn + rb. But if ra = rb then you have that a-b = (p-q)n = kn i.e. a-b is an integer multiple of n.

Therefore, you can always add or subtract any integer muptiple of ##n## to either ##a## or ##b##, for instance
if ##a \equiv b ## (mod ## n ##) , then:
##a \equiv b + n ## (mod ## n ##)
##a + n\equiv b ## (mod ## n ##)
etc
So in your case, you can add 26 to -3, you can add 52, subtract 26, subtract 52 and so on, and still have the same remained when dividing with 23

Last edited:
topsquark
I think it should be -3 itself. As it's not divisble by 26. Just like if it was 3%26, it'd be 3.
What are the possible answers for a "remainder" on division by 26? Is it the set ##\{-25, -24 \dots -1, 0, 1, \dots 24, 25\}##?

PS how is "remainder" defined?

malawi_glenn
##a \equiv b ## mod##(n)## means that ##(a-b)## is an integer multiple of ##n## i.e. ##a-b = kn## for some integer ##k##.
I think you mean ##a \equiv b \pmod n ## means that ##(a-b)## is an integer multiple of ##n## i.e. ##a-b = kn## for some integer ##k##. The placing of the parentheses (in this case automatic through use of the \pmod symbol) is important.

However the OP is asking about something subtly different, the value of b where ## b = a \text{ mod } n ##. This is defined as the unique integer ## b \in \{0 \dots n-1\} ## for which ##a \equiv b \pmod n ## is true: for positive integers this is the same as the remainder on division by ## n ## but for negative integers this is not the case.

Last edited:
malawi_glenn, vela and topsquark
Yes i wrote the paranthesis wrong thanks

If we are talking about modular arithmetic, then technically ##-3## is the additive inverse of ##3##, which is ##23## in this case. So:$$-3 \equiv 23 \ (mod \ 26)$$The simpler concept of a remainder is usually defined as a non-negative integer (although not always). In the usual case, we would have:
$$-3 = (-1 \times 26) + 23$$

SammyS, FactChecker, topsquark and 1 other person
As a simple analogy, I like to think in terms of a 12 hour clock.

Clocks read hours as 1,2,3,4,5,6,7,8,9,10,11,12 only.

Hence -3 hours would be 9 o'clock.

malawi_glenn and shivajikobardan

shivajikobardan
However the OP is asking about something subtly different, the value of b where ## b = a \text{ mod } n ##. This is defined as the unique integer ## b \in \{0 \dots n-1\} ## for which ##a \equiv b \pmod n ## is true: for positive integers this is the same as the remainder on division by ## n ## but for negative integers this is not the case.

Never seen ## b = a \text{ mod } n ## in my life, that you use an equal sign that is.
I have seen it when you deal with equivalence classes though.

I have only seen it being stated like this
"Find the smallest positive integer ##x## that solves ##x \equiv -18 \pmod {12}##"
or
"What is the smallest positive remainder when -18 is divided by 12" or "principal remainder"

shivajikobardan
Some programming languages use the % operator for modulo operations.

x = 25 % 15

shivajikobardan
yes it's CS. didn't know math and CS were different for modulo.
Writing a = b (mod n) is an abomination!

Writing a = b (mod n) is an abomination!
Yes it would be, but no-one has done that. As I said, parentheses (and the equivalence relation vs equality) are important here to distinguish between the two forms.

Yes it would be, but no-one has done that. As I said, parentheses (and the equivalence relation vs equality) are important here to distinguish between the two forms.
You did so in post 7.
However the OP is asking about something subtly different, the value of b where b=a mod n.
Never seen that notation.

You did so in post 7.
No I didn't.

Never seen that notation.
You already said that in #12, which is why I explained it to you.

yes it's CS. didn't know math and CS were different for modulo.
How a computer language works is at the discreption of the developers of that language. In Python, for example:
$$-3\%26 = 23$$Which is what I would have hoped.

malawi_glenn
More correctly in Python the expression would be:

Python:
-3%26 == 23

as single equals is for assignment x-y ie assign the value of y to x.

and double equals is for equality as in x==y meaning the value of x is equal to the value of y

An example python program:

Python:
for x in range(-50,50):
y=x%26
print("%d  %d"%(x,y))

One thing to note in python is that the % operator takes on different uses depending on how it is used:
- as a modulo operator y=x%26
- as a format specifier as in %d for printing an integer
- as a string formatting operator to apply the tuple to the format string "%d %d"

malawi_glenn and PeroK
This was my Python program:
Python:
print(-3%26)

malawi_glenn