{模板}快速幂

long long sqr(long long x)
{
    return (x*x)%moder;
}
long long power(long long a,long long b)
{
    if (b==0) return 1;
    if (b==1) return a;
    return (sqr(power(a,b/2))*power(a,b%2))%moder;
}

ll qsm(ll a,ll b)
{
    ll x = 1;
    a %= Mo;
    while (b)
    {
          if (b & 1) x = (x * a) % Mo;
          b >>= 1;
          a = (a * a) % Mo;
    }
    return x;
}

int Qsm(int a,int b)
{
    int x = 1;
    while (b > 0)
    {
          if (b & 1) x = (long long)x * a % Mo;
          b >>= 1;
          a = (long long)a * a % Mo;
    }
    return x;
}

你可能感兴趣的:(快速幂,模板)