Doubt in power function

here as x=(a%m) and y=b%(m-1) and x and y are already computed with %m in stringtoint fun then why in power fun we are computing %m everywhere? there we simply want x^y then ?

and x^y itself is (A^b)%m .so then we simply have to do x to power y only right?

hello @mansi25

this is done to avoid range overflow .

read about modular exponentiation technique it will make more sense to u.

but i think we do %m in every step if we want (x^y)%m ? then here simply to calculate x^y why we are taking %m.won’t it then calculate (x^y)%m?

no x^y can overflow na?
to avoid it we are using mod on evry step

but in ans we want only x^y?

in modular exponentiation we wnted to compute (a^b)%m that is why we were taking %m everywhere but here we want only x^y then why

and to avoid overflow we have already taken %m in stringtoint fun everywhere

once read this ->article

it will make ur doubt clear

image

here to calculate a^(m-2) % m we need to use modular exponentiation

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.