CP-Snippets

modpow

ll modpow(ll a, ll b){
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1) res = res * a % m;
        a=a*a%m;
        b>>=1;
    }
    return res;
}