Home > Technology > Modulus 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 Tags:
  1. Darkky
    May 4th, 2012 at 08:20 | #1

    Awesome Stuff Dude!! šŸ™‚ Helped me a lot in ECC

  2. November 19th, 2013 at 17:17 | #3

    Thnx dude šŸ™‚

  3. sanju
    March 13th, 2014 at 16:14 | #4

    thank u

  4. October 3rd, 2014 at 15:46 | #5

    That was quick and direct too, it really helped me

  5. qweqwe
    November 30th, 2014 at 13:56 | #6

    was looking for this 20 mins couldnt understand whats going on came here and boom , thanks

  6. aimi
    August 25th, 2015 at 04:27 | #7

    thanks a lot..

  7. sarah
    July 25th, 2016 at 22:26 | #8

    thank u

  8. Renu Mehra
    August 5th, 2016 at 20:56 | #9

    Thank you , It is helpful,

  9. Jack
    October 9th, 2016 at 07:16 | #10

    Very helpful. Thank you

  10. October 20th, 2016 at 23:12 | #11

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

  11. Shruti
    November 6th, 2016 at 04:21 | #12

    Very useful.. thank you

  12. March 9th, 2017 at 08:04 | #13

    explain (10)%(-3) please

  13. surabhi
    April 15th, 2017 at 04:03 | #14

    I was trying to find an answer since long! So happy, Thanks!

  1. No trackbacks yet.