Advertisement
karbaev

binpow

Feb 29th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.22 KB | None | 0 0
  1. int binpow (int a, int n) {
  2.     int res = 1;
  3.     while (n)
  4.         if (n & 1) {
  5.             res *= a;
  6.             --n;
  7.         }
  8.         else {
  9.             a *= a;
  10.             n >>= 1;
  11.         }
  12.     return res;
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement