Modular Exponentiation

#include
#include<math.h>
using namespace std;
int mod=100000;
int power(int a,int b,int n){
int res=1;
if (a >= mod)
a %= mod;
while ( b > 0 ) {
if (b & 1)
res=res*a;
if (res>=mod)
res %= mod;
if (a >= mod)
a %= mod;
a = a * a;
b=b>>1;
}
return res%n;
}
int main() {
int a,b,n;
cin>>a>>b>>n;
int c=power(a,b,n);
cout<<c;
return 0;
}

It does’nt pass all the test cases. What’s the problem with the code?

Your mistakes

  1. you have to take mod with n (third variable which you take as parameter in function) don’t define other variable

  2. use long long int

Modified Code