Let $$$m$$$ be some positive integer (not necessary prime) . There is a way to calculate $$$\displaystyle{\frac{a}{b}}\%m$$$ when b is not very big and $$$a \% b = 0$$$ Firstly, let's notice, that $$$\displaystyle{\frac{a}{b}}=mk+(a/b)\%m$$$, for some integer value k. Now, let's do some mathematical stuff:
So, the answer is $$$(a\%mb)/b$$$
If a%b = 0, then won't I first calculate a/b and then find (a/b) modulo m, so is this formula useful practically?
Yes, $$$a$$$ can be very big. For example $$$\frac{10^n-1}{9} \% m$$$
Why is "when $$$b$$$ is not very big" required?
This proof is correct even for large $$$b$$$ right?
For big $$$b$$$ you need to use BigInteger because you can't make something like this $$$b\%=m$$$
This can be generalized, when $$$a \%b$$$ can differ from $$$0$$$. Let $$$\gcd (b,m)=1$$$ for simplicity. We only want to calculate $$$b^{-1}$$$ (the inverse). We can find $$$p,q$$$ such that $$$pb + qm = 1$$$ with extended Euclidean algorithm. $$$q$$$ is not important, but $$$p$$$ will exactly be equal to the inverse. So, $$$\frac{a}{b} = ap\% m$$$.
If I wanted $$$\frac{1}{2} \pmod{11}$$$, is the answer $$$(1 \text{ mod } 22)/2$$$?
OP's precondition state that
a % b = 0
to use this.I missed that. This is a cool idea then!
Yes this seems correct. 1/2(mod 11) = 1/2 = (1 mod 22)/2.