Explanation of 1 mod 3
Solution 1
The remainder in 1%3
refers to what remains of 1
(not 3
) after you divide by 3
. As you have already said, 3
goes into 1
zero times. So -- when you remove 0
multiples of 3
from 1
, all of 1
remains. Thus 1 % 3 = 1
.
Solution 2
The result of a modulo operation n % m
is just that number r
for which q * m + r = n
(q
may be anything). The only requirement we have is that 0 <= r < m
.
So for instance:
7 % 5 --> 1 * 5 + 2 == 7 --> r = 2
1 % 3 --> 0 * 3 + 1 == 1 --> r = 1
Jay
Senior Javascript Engineer. ReactJS/ Context API Redux/ Redux Sagas/ Jest/ Enzyme/ React Testing Library ES6 css3 HTML
Updated on July 14, 2022Comments
-
Jay almost 2 years
So i've been looking into modulo recently. I'm trying to improve my math skills, which are not the best if i'm honest. But something i am trying to improve. I understand how this works i think. I am also quite competent with long division. However something is bugging me and i can't seem to find an answer for it online.
I know that 7 % 5 = 2 (5 goes into 7 once, with a remainder of 2).
What i don't understand is this;
1 % 3 = 1
How can this be, 3 goes into 1, 0 times, with a remainder of 3? Surely the answer to 1 % 3 = 3?
Can anyone explain this in its most simplest terms please?
Am i correct in thinking that if the dividend (1) is less than the devisor (3) which we know will equal 0 remainder x, it just uses the dividend as the result?
Thanks for your help.
-
Jay almost 7 yearsSorry as i said, my maths is not the best i dont fully understand. My thinking is clearly wrong but in my head i am doing 1 / 3, if i was to write this out as long division i would get 0 r 3, as modulos gets the remainder i still do not fully understand how the answer is not 3.