#include<iostream>
using namespace std;
#define L long long int
L anik(L b, L p, L m)
{
if(p == 0)
return 1;
else if(p%2 == 0)
{
return(anik(b, p/2, m))%m * (anik(b, p/2, m))%m;
}
else
return ((b%m) * anik(b, p-1, m))%m;
}
int main()
{
L base, pow, mod, ar;
while(cin >> base >> pow >> mod)
{
ar = anik(base, pow, mod);
cout << ar << endl;
}
return 0;
}
using namespace std;
#define L long long int
L anik(L b, L p, L m)
{
if(p == 0)
return 1;
else if(p%2 == 0)
{
return(anik(b, p/2, m))%m * (anik(b, p/2, m))%m;
}
else
return ((b%m) * anik(b, p-1, m))%m;
}
int main()
{
L base, pow, mod, ar;
while(cin >> base >> pow >> mod)
{
ar = anik(base, pow, mod);
cout << ar << endl;
}
return 0;
}
Comments
Post a Comment