Algorithm-Library

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

View the Project on GitHub UScuber/Algorithm-Library

:heavy_check_mark: math/modpow.hpp

Verified with

Code

ll modPow(ll a, ll n, ll p){
  a %= p;
  ll res = 1;
  while(n){
    if(n & 1) (res *= a) %= p;
    (a *= a) %= p;
    n >>= 1;
  }
  return res;
}
#line 1 "math/modpow.hpp"
ll modPow(ll a, ll n, ll p){
  a %= p;
  ll res = 1;
  while(n){
    if(n & 1) (res *= a) %= p;
    (a *= a) %= p;
    n >>= 1;
  }
  return res;
}
Back to top page