#include<iostream>
#include<cmath>
using namespace std;
int BigMod(long int b, int long p, int long m){
if(p == 0){
return 1;
}
if((p % 2) == 0){
return (BigMod(b,p/2,m)*BigMod(b,p/2,m)) % m;
}
return (BigMod(b,p-1,m)*(b%m)) % m;
}
int main(){
long int b,p,m;
while(cin >> b >> p >> m){
long int result = BigMod(b,p,m);
cout << result << endl;
}
return 0;
}
#include<cmath>
using namespace std;
int BigMod(long int b, int long p, int long m){
if(p == 0){
return 1;
}
if((p % 2) == 0){
return (BigMod(b,p/2,m)*BigMod(b,p/2,m)) % m;
}
return (BigMod(b,p-1,m)*(b%m)) % m;
}
int main(){
long int b,p,m;
while(cin >> b >> p >> m){
long int result = BigMod(b,p,m);
cout << result << endl;
}
return 0;
}
No comments:
Post a Comment