Modular Exponentiation problem

please see what is the error

@Bansaljatin05
You are performing multiplication instead of exponentiation. a should be multiplied with res instead of being added.
res*=a;
res=res%c;

Also note that your res variable is uninitialised in the beginning. Initialise it to 1.
Note that your code works in O(n) time while this problem can be solved in O( log n ) time. Try to optimise this. One way of doing this is through recursion. Think about it.

1 Like

now also not getting submitted

@Bansaljatin05
Write it like this
res*=a;
res = res%c;

Sir aise bhi galat aa rha hai,i tried it like this also

@Bansaljatin05
I submitted the code with this exact modification and I got a full score. Try again after making the above mentioned modifications and if it still doesn’t work , share your updated code with me here.