How do you compute $\frac{p}{qrs} \mod M$?

40 Views Asked by At

I would like to find $\frac{p}{q\space \space\space r\space \space s} \mod M $ . As multiplication of denominator can become large .
So , $\frac{p}{q\space \space\space r\space \space s} \mod M $ = $\frac{a}{b\space \space\space c\space \space d} \mod M $ , where $a = p\mod M$ , $b = q \mod M$ , $c = r \mod M$ , $d = s \mod M$ .
And convert (${b\space c\space d}$) to (${m\space d}$) where m=$(b\space c)mod M$
And this can further reduced to n where n = $(m\space d)mod M$
so now we have $\frac{a}{n}$ it can be computed using inverse modulo .
According to Wikipedia we can find $\frac{a}{b} \mod M$ when b and M are co-prime . But here it may or may not be co-prime. Is this correct way to evaluate $\frac{p}{q\space \space\space r\space \space s} \mod M $ ? If not then how we can evaluate this ?

1

There are 1 best solutions below

0
On

We can't because $\frac ab$ only makes sense if $\frac1b = b^{-1}$ (the multiplicative inverse of $b$) exists, in $\mathbb Z_M^\times$ this is the case iff $\gcd(b,M) = 1$. This works in your case as long as $\gcd(q,M) = \gcd(r, M) = \gcd(s, M) = 1$ and then you can compute their inverses individually and see $$\frac p{qrs} = pq^{-1}r^{-1}s^{-1} \pmod M$$ Where the inverses can be determined using the extended euclidean algorithm, giving you $k,m,\gcd(a,M)$ such that $$k\cdot M + m\cdot a = \gcd(a,M)$$ Where $m = a^{-1}$