// determine (n^p)%m
#include<iostream>
using namespace std;
long m,n,p;
long mod(long a,long b)
{
if(b==0)
return 1;
if(b%2==0)
{
long ret;
ret=mod(a,b/2);
return ((ret%m)*(ret%m))%m;
}
else
return ((a%m)*(mod(a,b-1)%m))%m;
}
int main()
{
while(cin>>n>>p>>m)
{
cout<<mod(n,p)<<endl;
}
}
#include<iostream>
using namespace std;
long m,n,p;
long mod(long a,long b)
{
if(b==0)
return 1;
if(b%2==0)
{
long ret;
ret=mod(a,b/2);
return ((ret%m)*(ret%m))%m;
}
else
return ((a%m)*(mod(a,b-1)%m))%m;
}
int main()
{
while(cin>>n>>p>>m)
{
cout<<mod(n,p)<<endl;
}
}
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন