TechnologyModulus of Negative Numbers

Modulus of Negative Numbers

The Quickest and easiest way to find the mod of a negative number is by using the below property

if a = (b) mod c then a = (c*k + b) mod c (where k = 1,2,3.......) 

It simply says that the value of a is unchanged when we add a multiple of c to b

Example

a = (10) mod 3 we all know that a = 1 Now
a = (3*1 + 10) mod 3 - a is still = 1
a = (3*2 + 10) mod 3 - a is still = 1
a = (3*3 + 10) mod 3 - a is still = 1
a = (3*4 + 10) mod 3 - a is still = 1

So adding any multiple of 3 (> 0) to 10 does not effect the value of a
Now we use this to our advantage in finding mod of negative numbers

Example

a = (-10) mod 3
Now i add 12 to 10 as 12 is a multiple of 3 and hence the value of a will remain unchanged

so a = (3*4 – 10) mod 3 = 2 mod 3 = 2

easy isnt it?

Another example

a = (-340) mod 60
So a = (60*6 – 340) mod 60 = (360-340) mod 60 = 20 mod 60 = 20

Categories: Technology

Comments

  1. surabhi

    April 15, 2017 4:03 am

    I was trying to find an answer since long! So happy, Thanks!
  2. March 9, 2017 8:04 am

    explain (10)%(-3) please
  3. Shruti

    November 6, 2016 4:21 am

    Very useful.. thank you
  4. October 20, 2016 11:12 pm

    But why this is done this way is still a mystery. What's the mathematica resoning behind this? Can anyone help please???
  5. Jack

    October 9, 2016 7:16 am

    Very helpful. Thank you
  6. Renu Mehra

    August 5, 2016 8:56 pm

    Thank you , It is helpful,
  7. sarah

    July 25, 2016 10:26 pm

    thank u
  8. aimi

    August 25, 2015 4:27 am

    thanks a lot..
  9. qweqwe

    November 30, 2014 1:56 pm

    was looking for this 20 mins couldnt understand whats going on came here and boom , thanks
  10. October 3, 2014 3:46 pm

    That was quick and direct too, it really helped me
  11. sanju

    March 13, 2014 4:14 pm

    thank u
  12. November 19, 2013 5:17 pm

    Thnx dude :)
  13. Darkky

    May 4, 2012 8:20 am

    Awesome Stuff Dude!! :) Helped me a lot in ECC
    1. May 4, 2012 12:41 pm

      i have lost touch with my math lately - glad it helped :)

Post a comment

Your email address will not be published. Required fields are marked *