Modular Exponentiation

#include
using namespace std;
int pow(int a,int n,int mod){

int res =1;
a=a%mod;
if(a==0)
return 0;
while(n){
if(n%2==0){
a=(aa)%mod;
n=n>>1;
}
else{
res=(res
a)%mod;
n–;
}

}
return res;
}
int main() {
int a,n,mod;
cin >> a>>n>>mod;
int ans = pow(a,n,mod);
cout<<ans<<endl;
return 0;
}
for the above i am getiin passed 8/9 test cases.where can i go wrong?

please use long long, instead of int