#include<bits/stdc++.h>
int bigmod(int b , int p , int m);
using namespace std;
int main()
{
int a , b , c;
while(cin>>a>>b>>c)
cout<<bigmod(a,b,c)<<endl;
return 0;
}
int bigmod(int b, int p, int m)
{
if(p==0)
return 1;
else if(p%2!=0){
int p1=b%m;
int p2=(bigmod(b,p-1,m))%m;
return (p1*p2)%m;
}
else{
int p1=(bigmod(b,p/2,m))%m;
return (p1*p1)%m;
}
}
int bigmod(int b , int p , int m);
using namespace std;
int main()
{
int a , b , c;
while(cin>>a>>b>>c)
cout<<bigmod(a,b,c)<<endl;
return 0;
}
int bigmod(int b, int p, int m)
{
if(p==0)
return 1;
else if(p%2!=0){
int p1=b%m;
int p2=(bigmod(b,p-1,m))%m;
return (p1*p2)%m;
}
else{
int p1=(bigmod(b,p/2,m))%m;
return (p1*p1)%m;
}
}
No comments:
Post a Comment