Advertisement
keverman

Modular exponentation

Feb 9th, 2020 (edited)
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.19 KB | None | 0 0
  1. ll mpow(ll base, ll exp, ll mod)
  2. {
  3.     ll res = 1;
  4.     while(exp) {
  5.         if(exp & 1) res = (res * base) % mod;
  6.         base = (base * base) % mod;
  7.         exp >>= 1;
  8.     }
  9.     return res;
  10. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement