math - what is the result of modulo opeartion on (a-b)%n -


recently solved problem have compute (a-b)%n.the results self explanatory when a-b positive number negative numbers results got seems confusing..i wanted know how can calculate result negative numbers.

any links dealing modulo operator properties welcome.

http://en.m.wikipedia.org/wiki/modulo_operation

in many programming languages (c, java) modulo operator defined modulus has same sign first operand. means following equation holds:

(-a) % n = -(a % n) 

for example, -8%3 -2, since 8%3 2.

others, such python, compute % n instead positive remainder when diving n, means

(-a) % n = n - (a % n) 

for example, -8%3 1 because 3-(8%3) 3-2 1.

note in modular arithmetic adding or subtracting multiple of n not change result because "equality" (or congruence if prefer term) defined respect divisibility: x equal 0 if multiple of n, , equal b if a-b multiple of n. example -2 equal 1 modulo 3 because -2-1 = -3 divisible 3.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -