The code is running fine, but only 4 test cases are being passed.
Here is the code
Doubt in Modular Exponentiation
Hello @ratulhans,
The failure of code is due to the following reason:
The maximum value a and b can have is 100000.
What you are are doing is a^b i.e. 100000^100000.
Is there any datatype available to store this big(infinitely big) value?
No, is the answer.
This, is the reason you are getting wrong output. If you want to verify this, then I would suggest you to print ans and see what it print.
Think of a different way to calculate modular exponential.
Hint:
A^B mod C = ( (A mod C)^B ) mod C
Refer the below mentioned link for details:
Hope, this would help.
Give a like, if you are satisfied.
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.