C++ 代码
#include<iostream>
using namespace std;
typedef long long LL;
LL res=1;
LL binary(LL a,LL b,LL c)
{
if(b==0)
return 1%c;
if(b&1) return res=a*binary(a,b-1,c)%c;
else
{
LL sum=binary(a,b>>1,c);
return sum*sum%c;
}
}
int main()
{
LL a,b,c;
scanf("%lld%lld%lld",&a,&b,&c);
printf("%lld",binary(a,b,c));
return 0;
}