program_contest_library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub ferin-15/program_contest_library

:warning: math/modpow.cpp

Back to top page

Code

// BEGIN CUT
ll modpow(ll x, ll y, ll m) {
    ll a = 1, p = x;
    while(y > 0) {
        if(y%2 == 0) {p = (p*p) % m; y /= 2;}
        else {a = (a*p) % m; y--;}
    }
    return a;
}
// END CUT

#line 1 "math/modpow.cpp"
// BEGIN CUT
ll modpow(ll x, ll y, ll m) {
    ll a = 1, p = x;
    while(y > 0) {
        if(y%2 == 0) {p = (p*p) % m; y /= 2;}
        else {a = (a*p) % m; y--;}
    }
    return a;
}
// END CUT

Back to top page