Please resolve my failed test cases

Five of my test case are not giving correct answer, kindly analyze my code and help me to rectify it by finding all the corner cases . Link to my code – https://ide.codingblocks.com/s/192737

hi,
I do not understand the logic of the for loop that u have written inside the function , if u could elaborate on that

it is a simple logn time complexity question
i have attached the code for ur reference

long int res=a%c; for(long int i=2;i<=b;i+=2) { res=(res*res)%c; } In this loop I am calculating the power of a^b in steps of 2 by calculating square of the remainder and then again taking modulus of that. Btw, your solution helped me, it uses almost the same logic but doesn’t recalculates the power of a every time from zero. Thanks.

1 Like

There`s a video by prateek bhaiya covering fast power. u could watch that too.