compute p^q mod c
where,
test cases <=100
p,q,c<=100
how to solve this problem?
I have tried this but getting wrong ans, is there any other way?
#include
using namespace std;
int main() {
int t;
cin>>t;
while(t–)
{
int p,q,c;
cin>>p>>q>>c;
int ans = 1;
for(int i=0; i<q; i++){
ans = (ans*p)%c;
}
cout<<"Result = "<<ans;
if(t!=0) cout<<endl;
}
return 0;
}