#include<bits/stdc++.h>
using namespace std;
int b,p,k;
int cp(int p)
{
int temp;
if(p==0)
return 1;
temp=cp(p/2)%k;
temp=(temp*temp)%k;
if(p%2==1)
temp=(temp*b)%k;
return temp;
}
int main()
{
cin>>b>>p>>k;
if(p==0)
{
cout<<b<<"^"<<p<<" mod "<<k<<"="<<0<<endl;
return 0;
}
int temp=b;
b%=k;
cout<<temp<<"^"<<p<<" mod "<<k<<"="<<cp(p)<<endl;
return 0;
}
快速幂
最新推荐文章于 2022-03-10 18:32:39 发布