Please tell me the modulus operation on multiplication of three numbers.
i.e.
(a*b*c)%m=?
result of modulus is a remainder of division
parentheses are not needed in your example since computation goes from left to right:
a * b * c % m = x
one possible solution:
x = a * b * c / m - static_cast<int>(a * b * c / m)
I want to prevent overflow of range..so i want the solution in terms of modulus operator i.e. modular arithmetic.
Is this correct ?
a*b*c%m=((a%m)*(b%m)*(c%m))%m
1 2
|
(a*b) % m == ( (a%m) * (b%m) ) % m
(a*b*c)%m == ( ( ((a%m)*(b%m))%m ) * (c%m) ) % m
|
Last edited on