Skip to content
Related Articles

Related Articles

Improve Article

Modular Addition

  • Last Updated : 12 Aug, 2020
Geek Week

Below are some interesting properties of Modular Addition: 
 

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

Example 1: 
Find the remainder of 22 + 26 + 29 when divided by 5. 
Solution: 
On dividing 22 by 5 we get 2 as remainder. 
On dividing 26 by 5 we get 1 as remainder. 
On dividing 29 by 5 we get 4 as remainder. 
Remainder of the expression (22 + 26 + 29)/5 will be equal to (2 + 1 + 4)/5. 
Combined remainder will be equal to remainder of 7/5 i.e. 2. 

Example 2: 
Find the remainder of 1234 + 5678 + 1478 when divided by 11. 
Solution: 
On dividing 1234 by 11 we get 2 as remainder. 
On dividing 5678 by 11 we get 2 as remainder. 
On dividing 1478 by 11 we get 4 as remainder. 
Rem [(1234 + 5678 + 1478)/11] = Rem [(2 + 2 + 4)/11] 
Rem [8/11] = 8. 

How is it useful? 
If we need to find remainder of addition of two large numbers, we can avoid doing the addition of large numbers, especially helpful in programming where addition of large numbers can cause overflow. Like in C, C++ programming languages if addition of two large numbers exceed 10^18 then overflow happens and we start getting unexpected results. 



Proof: Here we will prove for two numbers and thus it can be generalized for more than two numbers. 
 

Let a % m = r1
and b % m = r2 

Then a and b can be written as (using quotient theorem).  
Here q1 is quotient when we divide a by m and r1 is remainder. 
Similar meanings are there for q2 and r2
a = m x q1 + r1
b = m x q2 + r2

LHS = (a + b) % m

    = ((m x q1 + r1 ) + (m x q2 + r2) ) % m

    = (m x (q1 + q2) + r1 + r2 ) % m

We can eliminate the multiples of m when we take the mod m.
Then,
LHS = (r1 + r2) % m

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

    = (r1 + r2) % m

Hence, LHS = RHS

 

Attention reader! Don’t stop learning now.  Practice GATE exam well before the actual exam with the subject-wise and overall quizzes available in GATE Test Series Course.

Learn all GATE CS concepts with Free Live Classes on our youtube channel.

My Personal Notes arrow_drop_up
Recommended Articles
Page :