Question about modulus order of operations

40 Views Asked by At

I have maybe a simple question but I haven't been able to find an answer through googling.

The question is as such:

Is $\ a × b^2 \bmod c $ the same as $\ (a \bmod c) × (b^2 \bmod c) $?

That's it. That's all I'm confused about.

Sorry if it seems a little simple...

answer:

$\ a × b^2 \bmod c = ((a \bmod c) × (b^2 \bmod c))\bmod c $

:)

2

There are 2 best solutions below

3
On BEST ANSWER

Where does the second product even take place? If it is over the integers then definitely no. $$2 \times 3^2 \pmod 6$$ is zero but $$2 \pmod 6$$ and $$3 \pmod 6$$ are just two and three. Thus their product will be 6.

If the second product is not taken over the integers, and everything is modulo c in the end, then it does not matter if you reduce $a$ and $b^2$ before or after you multiply.

6
On

Generally no. Distributive property here does not apply although there would be coincidental instance when it will hold.

Let

$ab^2\bmod c= r$

$a\bmod c= p$

$b^2\bmod c= q$

Then your question would imply that $r=pq$

Where $$r=\frac {ab^2}{lc}$$ $$p=\frac {a}{mc}$$ $$q=\frac {b^2}{nc}$$

$l,m,n$ are integers

Thus implies

$$r=\frac{ab^2}{lc}=(\frac{a}{mc})(\frac{b^2}{nc})=\frac{ab^2}{mnc^2}$$ Only true when $l=mnc$