Modular__exponentiation


why my code is failing for some test cases?

@rajukumarbhui after multiplying ans with n, you have to check whether value of ans is either greater than c or not. If the value of ans come out to be greater than c than you have to take the reminder of ans with c. Add the follow condition in your code after line 11 :
if(ans>=c){
ans%=c;
}

hope this helps.

sir now ,my code only failing for test case 6

try changing data type from int to long long int and let me know if that works

sir i think checking ans>c at line 11,doesn’t matter because if it is below c ,ans should remain the same.But i tried still giving wrong answer

sir it is working with with long long int .thanks

1 Like

@rajukumarbhui Most welcome :slight_smile:
If your query is solved I request you to mark it as resolved.
Thank you.

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.