Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- // O(log2(exp))
- int power(int base, int exp)
- {
- if(exp == 0)
- return 1;
- if(exp % 2 == 0)
- return power(base*base, exp/2);
- return base * power(base, exp-1);
- }
- int main()
- {
- cout << power(3, 1000000000);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement