快速幂模版(快速幂取模模版)
快速幂模板
#include<bits/stdc++.h>
using namespace std;
unsigned long long quick_mi(unsigned long long a,unsigned long long b,unsigned long long c)
{
if(b==1) return a;
unsigned long long l=quick_mi(a,b/2,c);
if(b%2==1) return ((l%c)*(l%c)*(a%c));
else return (l%c)*(l%c);
}
int main()
{
unsigned long long b,p,k;
cin>>b>>p>>k;
if(p==0)
{
cout<<b<<"^"<<p<<" mod "<<k<<"="<<1%k;
return 0;
}
cout<<b<<"^"<<p<<" mod "<<k<<"="<<quick_mi(b,p,k)%k;
return 0;
}