It is failing few test cases of modular exponentation

can you help me fix my code?

#include
using namespace std;
int power(int a,int b)
{
int ans=1;
while(b>0)
{
int last_bit=(b&1);
if(last_bit)
{
ans=ansa;
}
a=a
a;
b=b>>1;
}
return ans;
}
int main() {
int a,b,c;
cin>>a>>b>>c;
cout<<power(a,b)%c;
return 0;
}

hello @jindaldivish
a) use long long

b) use modular property
i,e
ans=(ans%c * a %c)%c;

a=(a%c * a%c) %c

read about -> modular exponentiation technique

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.