#include<iostream>
using namespace std;
int loop(long long x,long long y)
{
if(y==0)
{
return 1;
}
long long res=1;
while(y)
{
if(y&1)
{
res=res*x;
}
x=x*x;
y>>=1;
}
return res;
}
int main()
{
long long a,b,p,q,w;
cin>>a>>b>>p;
q=loop(a,b);
w=q % p;
cout<<a<<"^"<<b<<" "<<"mod"<<" "<<p<<"="<<w<<endl;
}
这种不行吗?