Unable to clr all testcases


Whats wrong with my code?

Hi… ur ans may go out of range of even long long… refer this solution

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.

how is this part working? ans = (ans * a) % c;

take mod every time u multiply a to handle the case that ans don’t overflow

yes but how is (((1*2)%3)*2)%3 working and providing the right ans?

try to dry run using pen paper… u would get the logic… there is no rocket science in this question

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.