快速幂模板
快速幂求n^n:
int f1(int a,int b)
{
int t=1;
while(b)
{
if(b % 2 != 0)
{
t*=a;
b--;
}
a*=a;
b/=2;
}
return t;
}
快速幂求n^n后y位:
int f2(int a,int b)
{
int t=1;
while(b)
{
if(b % 2 != 0)
{
t=(t*a)%x; //x控制要求的位数
b--;
}
a=(a*a)%x;
b/=2;
}
return t;
}