Advertisement
fooker

binary exponentiation

Nov 19th, 2022
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.19 KB | None | 0 0
  1. ll binaryexponentiation(ll x, ll y, ll m){
  2.     assert(y>=0);
  3.     ll res=1;
  4.     x%=m;
  5.     while (y>0){
  6.         if (y%2==1) res=res*x%m;
  7.         x=x*x%m;
  8.         y/=2;
  9.     }
  10.     return res;
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement