Tuesday, 16 September 2014

Properties of modulus operator

Properties of modulus operator

(a+b)%m=(a%m+b%m)%m

(a*b)%m=(a%m+b%m)%m

modulus of a (negative) number

 (a%b+b)%b
     where a<0


NOTE: modulus operator gave wrong values in case of division


 example=(a/b)%m is not calculate directly
 
  (a/b)%m=  (a%m*inverse(b)%m)%m

  where inverse of b=b^(m-2)%m  
 
here m is a prime number.

No comments:

Post a Comment