Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find modulo of a sum of numbers?

Tags:

c++

math

modulo

I am seeking for a way to find modulo of a sequence of numbers like: (a1 + a2 + a3 + a4 + ... + an) mod x

Is there any way/property of modulo function so that I can compute mod of this sequence from the individual mods of numbers in sequence.

like image 391
nole Avatar asked Oct 12 '14 08:10

nole


People also ask

How do you find the sum of a mod?

Case 1: When N < K, for each number i, N >= i >= 1, will give i as result when operate with modulo K. So, the required sum will be the sum of the first N natural number, N*(N+1)/2.

What is modulo sum?

Now here we are going to discuss a new type of addition, which is known as “addition modulo m” and written in the form a+mb, where a and b belong to an integer and m is any fixed positive integer. By definition we have. a+mb=r,for0⩽r<m.

What is the formula of modulo?

Mathematically, the modulo congruence formula is written as: a ≡ b (mod n) , and n is called the modulus of a congruence. where r is a common remainder.

What is the modulus of 10 and 2?

10 modulus 2 stands for the Euclidean division discussed, defined and explained in full detail on our home page. 10 is the dividend, 2 is the divisor (modulo), 5 is the quotient explained below, and 0 is called the remainder. The division rest of 10 by 2 equals 0, and the value of the quotient is 5.


1 Answers

Mod operator is distributive;

( x + y ) % z

... is equivalent to:

( x % z + y % z ) % z
like image 90
ravi Avatar answered Oct 06 '22 07:10

ravi