My code is getting TLE in Test Case 4, I can’t figure out how? Will you please see it?
Math Day Problem
hi @Rhinorox, there is a slight optimization you can do in your pow function , in case b&1==1
for that case you can return temp*temp*a
instead of a*power(a,b-1,m)
corrected code :-
ll power(ll a, ll b, ll m)
{
if(b==0) return 1;
ll temp=power(a,b/2,m);
if(b&1) return ( (a%m) * (temp%m * temp%m)%m)%m;
else
{
return ( (temp%m) * (temp%m) )%m;
}
}
Since, constraints are quite strict in this question ,even a slight modification helps
In case of any doubt feel free to ask
Mark your doubt as RESOLVED if you got the answer
still getting TLE in that same test case
refer complete code :- https://ide.codingblocks.com/s/285683
i am getting all correct for the submission
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.