I know, this is very simple and dumb question, i just cannot come to understand, the problem is:
Why and how happens this in mathematics?
−5(mod4)=3
I know how to get this for positive numbers, but how does it work for negative ones.
I need the explanation of what happens in the background when solving this. Is it the distance from 0 to 4?
Answer
Since you seem to be using "mod" as a binary operator rather than as the context for a congruence relation, let's define "mod" precisely: assuming b>0,
amodb=a−b⌊a/b⌋
That is, amodb denotes the distance to a, from the largest multiple of b that is not greater than a. If you imagine the "number line" with the multiples of b all marked out, then amodb is the distance to the point a from the closest marked point on its left.
In your particular case, of −5mod4, note that the list of all integer multiples of 4 is: …,−20,−16,−12,−8,−4,0,4,8,12,16,20,24,…
In this list, the largest number (multiple of 4) that is to the left of −5 is −8. And the distance from −8 to −5 is 3; that is why we say that −5mod4=3.
(This is exactly the same way we would calculate 5mod4: in the list, the largest number that is to the left of 5 is 4, and the distance from 4 to 5 is 1, so we say 5mod4=1.)
No comments:
Post a Comment