取模运算性质:
(a+b)%p=(a%p+b%p)%p;
(a*b)%p=((a%p)+(b%p))%p;
快速乘:
typedef long long ll;
ll qc(ll a, ll k, ll p)
{
ll res = 0;
while (k)
{
if (k & 1) res = (res + a) % p;
a = (a + a) % p;
k >>= 1;
}
return res;
}
快速幂:
typedef long long ll;
ll qc(ll a, ll k, ll p)
{
ll res = 1;
while (k)
{
if (k & 1) res = (res * a) % p;//res=qc(res,a,p)
a = (a * a) % p;//res=qc(a,a,p);
k >>= 1;
}
return res;
}