MODULAR EXPONENTIATION


My code is not passing 6/10 test cases, kindly provide me a better code highlighting my mistakes.

Hello @yash_aryan i have corrected your code:


if you have any doubt you can ask here:
Happy Learning!!

Please explain the underlying logic/algorithm.

@yash_aryan i have not done anythin special this i have just corrected your code.
if you have any doubt in any part of the code:
we can discuss here:paste the part and ask.
Happy Learning!!

I had used the formula (ab)%m=((a%m)(b%m))%m. Which formula have u used? And why was my code not passing the test cases. What was the silly mistake that I did? Please explain.

@yash_aryan the major problem you were doing was that you were doing left shifting while we have to right shift it.
and aslo a should be multiplied outside the if part.
if you still have any doubt you can ask here:
Happy Learning!!

Thanks you so much :slight_smile:

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.