# Modular Arithmetic Examples

#### zulfi100

Joined Jun 7, 2012
633
Hi,
I am trying to solve some simple questions modular arithmetic following the techniques mentioned at:
Examples
(8+25)mod 12=(8 mod 12 + 25 mod 12 = 8 + 1=9
Now if I do this:
(5+9) mod 10 = 5 mod 10 + 9 mod 10 = 14

Somebody please guide what is the correct method in the above case?

Zulfi.

#### MrChips

Joined Oct 2, 2009
21,052
The mod operator is not distributive.

#### zulfi100

Joined Jun 7, 2012
633
Hi,

I found the formula:

\Q1. [ (8+25)mod 12 = [(8 mod 12) + (25 mod 12)] mod 12= [8 + 1] mod 12 = 9\

\Q2.(5 + 9) mod 10 = [(5 mod 10) + (9 mod 10)] mod 10 = [5 +9] mod 10 = 4 \

Zulfi.

#### WBahn

Joined Mar 31, 2012
25,738
Hi,
I am trying to solve some simple questions modular arithmetic following the techniques mentioned at:
Examples
(8+25)mod 12=(8 mod 12 + 25 mod 12 = 8 + 1=9
Now if I do this:
(5+9) mod 10 = 5 mod 10 + 9 mod 10 = 14

Somebody please guide what is the correct method in the above case?

Zulfi.
You can distribute the modulo reduction inward as much as you want, but you always need to do a final reduction at the end.

(a + b) mod N = ((a mod N) + (b mod N)) mod N

Be careful not to get carried away and distribute the reduction outward, which is not allowed (just like you can't distibute multiplication outward).

So

(a + b) mod N + c = ((a mod N) + (b mod N)) mod N + c

• zulfi100

#### WBahn

Joined Mar 31, 2012
25,738
The mod operator is not distributive.
Sure it is -- we wouldn't be able to do very many useful things if it weren't because the numbers involved in practical modular expressions would have so many digits we couldn't even store them, let alone work with them. It's just that the distributive rule for modular reduction retains the final reduction at the end.

• zulfi100