modular divsion causing difference in answer by using modulo arithmetic formula

22 Views Asked by At

We see that 25%2==1 but if we try to do (50/2)%2 by the formula:

(a / b) % c = ((a % c) * (b^(-1) % c)) % c

The first term a%c = 50%2 evaluates to zero, thus making the entire term zero. Where am i screwing?

1

There are 1 best solutions below

2
On

I'd say that the correct formula is something like

$\frac{a}{b} \bmod c = \frac{a \bmod c}{b \bmod c} \bmod c$

In your example this yields a $\frac{50 \bmod 2}{2 \bmod 2} \bmod 2 = \frac{0}{0} \bmod 2$ which can't be interpreted correctly.