Modular Exponentiation

why are my testcases failing?

hi @divyalamba910

1<=a,b,c<=100000

since the constraints are large u will have to use long long int instead of int and take modulus at each step to avoid overflow of ans…

refer this code -->

#include<iostream>
using namespace std;

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	
	long long ans = 1;
	for(int i=1;i<=b;i++){
		ans = (ans * a) % c;
	}
	
	cout<<(ans%c)<<endl;

	return 0;
}

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.