Advertisement
Mihai_Preda

Untitled

Feb 16th, 2021
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.30 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. // O(log2(exp))
  6. int power(int base, int exp)
  7. {
  8.     if(exp == 0)
  9.         return 1;
  10.     if(exp % 2 == 0)
  11.         return power(base*base, exp/2);
  12.     return base * power(base, exp-1);
  13. }
  14.  
  15. int main()
  16. {
  17.     cout << power(3, 1000000000);
  18.     return 0;
  19. }
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement