I am mode the corrections and was still getting the same error:

#include
using namespace std;

int fast_exponentiation(long int x, long int n)
{
long int ans=1,last_bit;

while(n>0)
{
	last_bit=(n&1);

	if(last_bit)
	{
		ans=ans*x;
	}

	x=x*x;
	n=n>>1;
}

return ans;

}

int main() {
long int a,b,c;
cin>>a>>b>>c;
long int ans=(fast_exponentiation(a,b))%c;
cout<<ans;
return 0;
}

as a and b are very large so you have to take mod in each step

other wise your a^b will overflow and then taking mod with not help