Modular exponentiation


Pls tell why am I not passing all the testcases

The approach you are following in your code is wrong, Use the approach as,
long long int result = 1;
while(b>0)
{
if
(b&1)
{
result = (resulta)%c;
}
a=(a
a)%c;
b=b>>1;
}

Try to follow this approach and then submit your code…

May I pls know the name of this algo, to study more about it. And if possible can you also pls tell one set of values which I was failing, so I can also alter my initial code in some other way(maybe not as efficient) to hone my skills

I have used the concept of bitmasking as it is given in the question that you need to calculate (a^b)mod c… …Your code was failing in many test cases.,
Like for eg,
Input : 5300 59 234
Expected Output : 224
Your output : -8

You can read more about the bitmasking in the bitmasking section… and then can implement your code accordingly…