The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

In my Data Structures textbook it says:

"We say that A is congruent to B modulo N, written A = B (mod N), if N divides A - B. Intuitively this means that the remainder is the same when either A or B is divided by N. Thus, 81 = 61 = 1 (mod 10)"

Does modulo mean that division using the number N yields the same remainder on both A and B?

"We say that A is congruent to B modulo N, written A = B (mod N), if N divides A - B. Intuitively this means that the remainder is the same when either A or B is divided by N. Thus, 81 = 61 = 1 (mod 10)"

Does modulo mean that division using the number N yields the same remainder on both A and B?

-9 = 81 = 61 = 1 (mod 10)

@ozo: if I understand correctly,

5 mod 3 = 2

4 mod 3 = 1

3 mod 3 = 0

2 mod 3 = 2

1 mod 3 = 1

0 mod 3 = 0

-1 mod 3 = 2

-2 mod 3 = 1

-3 mod 3 = 0

-4 mod 3 = 2

So the negatives are sort of backwards to the positives.

5 mod 3 = 2

4 mod 3 = 1

3 mod 3 = 0

2 mod 3 = 2

1 mod 3 = 1

0 mod 3 = 0

-1 mod 3 = -1

-2 mod 3 = -2

-3 mod 3 = 0

-4 mod 3 = -1

But if you add the divisor to the mod, it gives the same answer as before.

5 mod 3 = 2

4 mod 3 = 1

3 mod 3 = 0

2 mod 3 = 2

1 mod 3 = 1

0 mod 3 = 0

-1 mod 3 = 2

-2 mod 3 = 1

-3 mod 3 = 0

-4 mod 3 = 2

So the negatives are sort of backwards to the positives.

I'd say that the negatives follow exactly the same pattern as the positives

Whereas

In some places it goes like this:seems to be "backwards"

5 mod 3 = 2

4 mod 3 = 1

3 mod 3 = 0

2 mod 3 = 2

1 mod 3 = 1

0 mod 3 = 0

-1 mod 3 = -1

-2 mod 3 = -2

-3 mod 3 = 0

-4 mod 3 = -1

To me it makes no sense to have 5 different mod 3 classes

a mod b can be defined as

a - b*floor(a/b)

which works consistently for any sign of a or b, and even for non-integer a or b

All Courses

From novice to tech pro — start learning today.

the "remainder is the same" intuition works better with division operators that are defined so that the remainder is the same sign as the divisor