https://ide.codingblocks.com/s/193258 only 2 test cases are passing
Modular expension problem
so what to do in that case
@Learning_bunny,
Think like this, (a^b)%m will always be in the range [0,m-1], so if we never let any intermeditary values exceed m, so we can obtain the final result without any overflow. So now how do we do this, think this:
(a * b * c) % m = (((a % m) * (b % m) % m) * (c % m) %m) %m
Can you extend this for (a^b)%m i.e (a * a * a * … b_times) % m
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.