- yeyou26 的博客
[-]快速幂
- 2024-1-24 11:36:54 @
//lg 1226
//快速幂
#include<bits/stdc++.h>
using namespace std;
long long a,n,p;
long long nn;
long long qpow()
{
long long b=a;
long long ans=1;
while(n)
{
if(n&1) ans=ans*b%p;
n/=2;
b=b*b%p;
}
return ans;
}
int main()
{
// freopen("working.in","r",stdin);
// freopen("working.out","w",stdout);
cin>>a>>n>>p;
nn=n;
printf("%lld^%lld mod %lld=%lld",a,nn,p,qpow());
return 0;
}