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
  1. Darkky
    May 4, 2012 at 8:20 AM

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

    • May 4, 2012 at 12:41 PM

      i have lost touch with my math lately – glad it helped šŸ™‚

  2. November 19, 2013 at 5:17 PM

    Thnx dude šŸ™‚

  3. sanju
    March 13, 2014 at 4:14 PM

    thank u

  4. October 3, 2014 at 3:46 PM

    That was quick and direct too, it really helped me

  5. qweqwe
    November 30, 2014 at 1:56 PM

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

  6. aimi
    August 25, 2015 at 4:27 AM

    thanks a lot..

  7. sarah
    July 25, 2016 at 10:26 PM

    thank u

  8. Renu Mehra
    August 5, 2016 at 8:56 PM

    Thank you , It is helpful,

  9. Jack
    October 9, 2016 at 7:16 AM

    Very helpful. Thank you

  10. October 20, 2016 at 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???

  11. Shruti
    November 6, 2016 at 4:21 AM

    Very useful.. thank you

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: