问题
i have an equation ,
((a*b*c*d)/(e*f*g*h))%m
My question is , Can i first apply multiplication property
(a*b) mod(n) = (a*mod(n)) * (b*mod(n) ) mod(n)
to numerator and then denominator , so that numerator and denominator becomes a single value , and then solve the division operation?
(a/b) mod(n) = (a*inv(b)) mod(n)
回答1:
Let N = a*b*c*d
and D = e*f*g*h
. We want to calculate:
(N/D) mod n = (N * inv(D)) mod n
We can use the multiplication property here in the following way:
(N * inv(D)) mod n = ((N mod n) * (inv(D) mod n)) mod n
To calculate N mod n
we can apply the multiplication property again so the first part of answer is yes - you can apply the multiplication property to the numerator before solving the division because you will have to do it anyway.
The result of (inv(D) mod n)
is a number X
that satisfies the equation:
(D * X) mod n = 1
((D mod n) * (X mod n)) mod n = 1
If you apply the multiplication property to the denominator before solving the division you will get:
(((D mod n) mod n) * (X mod n)) mod n = 1
However (D mod n) mod n = D mod n
so it doesn't matter. It means that the second part of the answer is also yes - you can apply the multiplication property to the denominator before solving the division.
来源:https://stackoverflow.com/questions/26826787/modulus-operation-division-property