Modulus of a/b with m

During solving one question, I found out that (a*b)%m = ( (a%m) * (b%m) ) but same is not applicable with division, ie, (a/b) mod m != (a mod m) / (b mod m). Now I want to know what can we do in such cases to find (a/b) mod m efficiently such that there is no overflow ?

Hello @rishabhdevbanshi i think when you are akready dividing the numbers then result is already going to be small.
as it will be divided so you can simply do like that :
(a/b)%m.
Happy Learning!!

@rishabhdevbanshi but the you should not do modular division because in some cases the denominator can be congruent to zero and in that the case the result evaluated out to be will be 0 and that is not valid.
so that is why you will learn in your course further that the modular division is defined with the condition such that modular division is defined when the modular inverse of the divisor exist.
if you have any other doubt you can ask here:
Happy Learning!!

Actually the problem which I am solving says P⋅Q−1P⋅Q−1 modulo 998,244,353.
Now, I am struggling to find out , how it will be calculated.

P⋅Q−1 modulo 998,244,353, Q-1 is Q inverse.

@rishabhdevbanshi do you want me to evaluate this?

yes for p=34 and q=16. I want to know how it will be evaluated.

@rishabhdevbanshi see this:

Naah, ans is 873463811.
Pls refer this link for more understanding, maybe I am not able to convey to you what I want to tell properly.
Link : https://www.codechef.com/JAN21B/problems/RCTEXSCC

Refer to last paragraph of the question and sample cases for more clear understanding .

It is showing problem is not visible now.

please share the screenshot or copy paste the code.

Try to reopen 2-3 times. It should work else I’ll send screenshot.

you can see this:


Happy Learning!!

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.